Pages

About Lan Ahmad

My photo
Pendang, Kedah, Malaysia
It's all about my real life!!!

7 August 2012 - Tuesday

Testing PIC16F876A 28-Pin board to check RS232 Communication and LED C4 run properly. RS232 is use to connect PIC board to GSM Modem. If RS232 can't send data to GSM and receive data from GSM modem. To test this PIC board, i need to write program code that can observe the incoming character from PIC board.

#include <pic.h>
#use delay(clock=20000000)
#fuses hs,nowdt,nolvp,noprotect, nobrownout
#use rs232(baud=9600,xmit=pin_c6,rcv=pin_c7, parity=n)

void main()
{
int count=0;
while(true)
{
printf("\f**Welcome to Malaysia**\n\r");
printf("**counter value is %u **", count);
count+=1;
delay_ms(1000);
}
}

Then, PIC need to check the outgoing character from PC to PIC.
#include <pic.h>
#use delay(clock=20000000)
#fuses hs,nowdt,nolvp,noprotect
#byte portb=6
#byte portc=7
#use rs232(baud=9600,xmit=pin_c6,rcv=pin_c7, parity=n)
#include "flex_lcd.c"

int mystatus=0; //here can't declare byte coz not detected by compiler
char mydata;

void main()
{
int count=0;

lcd_init();
printf("Enter your character : A or S or Z or X");
lcd_gotoxy(1,1);
lcd_putc("Testing");

while(true)
{
if(kbhit()) //monitor incoming charactor from RS232
{
   mydata=toupper(getch()); //receive charactor dan save in mydata
   printf("\n\rYou entered: %c",mydata); //display on hyper terminal
   count++;
   mystatus=1;
}
if (mystatus==1)
{
if(mydata=='A')
{ output_high(pin_c4);
  lcd_gotoxy(1,2);
  lcd_putc("led on");
} //led on
if (mydata=='S')
{ output_low(pin_c4);
  lcd_gotoxy(1,2);
  lcd_putc("led off");
} //led off
if (mydata=='Z')
{ output_high(pin_c3);
  lcd_gotoxy(1,2);
  lcd_putc("relay on");
} //buzzer on
if (mydata=='X')
{ output_low(pin_c3);
  lcd_gotoxy(1,2);
  lcd_putc("relay off");
} //buzzer off
mystatus=0;
}//end if
}//end while
}//end void main