Saturday, February 16, 2013

Using PIC16F887 I/O to drive external devices

I’ve done a small addition to circuit on the previous circuit.I’m going to use LCD display I added there,to debug my project too.I’m taking out 6 I/O pins from the PIC16F877 via a connector to the breadboard.

Here is the modification to the previous schematic.

DSCF5562_800x600

I have written a sample code to check the functionality of the I/O pins by setting them to be ‘0’ logic level.The configuration bits are same as for the previous post. Note that the changes are in bold.

sbit LCD_RS at RB5_bit;
sbit LCD_EN at RB4_bit;
sbit LCD_D4 at RB3_bit;
sbit LCD_D5 at RB2_bit;
sbit LCD_D6 at RB1_bit;
sbit LCD_D7 at RB0_bit;

sbit LCD_RS_Direction at TRISB5_bit;
sbit LCD_EN_Direction at TRISB4_bit;
sbit LCD_D4_Direction at TRISB3_bit;
sbit LCD_D5_Direction at TRISB2_bit;
sbit LCD_D6_Direction at TRISB1_bit;
sbit LCD_D7_Direction at TRISB0_bit;

void main() {
    osccon = 0x70;
    ansel  = 0;
    anselh  = 0;
    trisa = 0;
    trisb = 0;
    trisc = 0;
    trisd = 0;
    Lcd_Init();

  Lcd_Cmd(_LCD_CLEAR);
  Lcd_Cmd(_LCD_CURSOR_OFF);
  Lcd_Out(1,1,"www.incredible");
  Lcd_Out(2,1,"diy.com");
 
  porta.f7=0;
  porta.f6=0;
  portc.f0=0;
  portc.f1=0;
  portc.f2=0;
  portc.f3=0;
  portd.f0=0;
  portd.f1=0;
 
  for(;;){
  portd.f4=1;
    delay_ms(1000);
  portd.f4=0;
  delay_ms(1000);
  }
   
}

Here’s how to use the circuit with the breadboard Winking smile

DSCF5563_800x600

No comments:

Post a Comment