As title, i'm doing a project tht require serial communicate btw pic and vb. I am new in serial communication require help and guide so that i manage to finished my GUI part within this week. My project hardware is turn on/off the sensors (indicate with leds)and buzzer . The remaining part is left with communicate the pic16f877a (by using hi-tech compiler c language) and vb2008. (COMM 7)
I have searched some sample code but majority are written in assembly
Below is my coding , i have try do my best . Hope some expert can help me correct it and sorry for the silly programming.
I have searched some sample code but majority are written in assembly
Below is my coding , i have try do my best . Hope some expert can help me correct it and sorry for the silly programming.
Rich (BB code):
#include<pic.h>
#include"delay.h"
#define PIC_CLK == 20000000
// define the frequency of oscillator used;choose either one
__CONFIG(0x3F32); //in this case might be not important because pin assignment has been defined
#define BAUD 9600
#define SPBRG 129
#define SW1 RB0
#define SW2 RB1
#define LED1 RB6
#define LED2 RB7
#define buzzer RB2
#define RX_PIN RC7
#define TX_PIN RC6
#define init_comms()
RX_PIN = 1;
TX_PIN = 1;
void putc(unsigned char);
unsigned char getc(void);
Is that correct ? If so do for "1" as well ?
void putc(unsigned char byte)
{
while(!TXIF)
TXIF = 0;
SBUF = byte;
}
unsigned char getc(void)
{
while(!RCIF)
RCIF = 0;
return SBUF;
}
//------function prototype-------//
void delayS(int sec);
void delaymS(int msec);
//----global variable---------//
//------main program-------//
void main()
{
int flag;
TRISB=0x03;
LED1=0;
LED2=0;
buzzer=0;
while(1)
{ //checking if the sw1 is pressed
if(SW1==0)
LED1=1;
if(SW1==1)
LED1=0;
if(SW2==0)
LED2=1;
if(SW2==1)
LED2=0;
if(LED1==1 || LED2==1)
buzzer=1;
else
buzzer=0;*/
}
}