hello I have a questoin about this code if someone can help me..
this is the code I have for my pic
#include <system.h>
#define PIC16F877A
#pragma CLOCK_FREQ 4000000
char data1;
void main ()
{
trisd=00000000b; //set port d as output
trisc=10000000b; //set port rc7 as input since the receiver
//rx is there
portc=0; //set port c to 0
portd=0; //same for d
intcon=11000000; //because I am using interrupts
sprg=27; //I am using a boud rate in computer and
//high speed formula in pic data sheet
//9600=4000000(16(x+1)), x=27.04 so i put 27
while (1) //loop so that the microcontroller keeps checking
{ //the signal that comes from the computer
portd=0; / /portd = 0 so that if the data1 is not 1100001 then the
//port d will not be on
txsta=00100100b; // to enable enterrupts and to use baoud rate
//high speed
rcsta=10010000b; //to enable the serial port asynchronous receiver
pie1=00100000b; // for using interrupts
//the rcif flag
// is set when reception is complete
data1=rcreg; //read rcreg where the signal bits are stored
if (data1==1100001) //or if the ascii of letter 'a' is received
{ //then the rd7 = high
portd=10000000;
}
}
}
and the plan that i have is to send a signal whith the computer using hyper terminal
so lets say i send the letter a and while a keep pressing it the computer is going to send the signals to the pic and while the pic is recieving the letter a portd 7 is going to be high or an led concected to it will be on and if i stop pressing the letter a the port d is not going to be high and the led will be off
so please tell me what i need to fix in my code because i know there are things wrrong maybe the while loop is not located correctly or a i do not know , I read the pic data sheet and i tryed to follow the steps to program the usart as it said but i do not know if its right
thank you i'll appreciate your help
this is the code I have for my pic
#include <system.h>
#define PIC16F877A
#pragma CLOCK_FREQ 4000000
char data1;
void main ()
{
trisd=00000000b; //set port d as output
trisc=10000000b; //set port rc7 as input since the receiver
//rx is there
portc=0; //set port c to 0
portd=0; //same for d
intcon=11000000; //because I am using interrupts
sprg=27; //I am using a boud rate in computer and
//high speed formula in pic data sheet
//9600=4000000(16(x+1)), x=27.04 so i put 27
while (1) //loop so that the microcontroller keeps checking
{ //the signal that comes from the computer
portd=0; / /portd = 0 so that if the data1 is not 1100001 then the
//port d will not be on
txsta=00100100b; // to enable enterrupts and to use baoud rate
//high speed
rcsta=10010000b; //to enable the serial port asynchronous receiver
pie1=00100000b; // for using interrupts
//the rcif flag
// is set when reception is complete
data1=rcreg; //read rcreg where the signal bits are stored
if (data1==1100001) //or if the ascii of letter 'a' is received
{ //then the rd7 = high
portd=10000000;
}
}
}
and the plan that i have is to send a signal whith the computer using hyper terminal
so lets say i send the letter a and while a keep pressing it the computer is going to send the signals to the pic and while the pic is recieving the letter a portd 7 is going to be high or an led concected to it will be on and if i stop pressing the letter a the port d is not going to be high and the led will be off
so please tell me what i need to fix in my code because i know there are things wrrong maybe the while loop is not located correctly or a i do not know , I read the pic data sheet and i tryed to follow the steps to program the usart as it said but i do not know if its right
thank you i'll appreciate your help