J_D
Joined: 24 Apr 2005 Posts: 1
|
Pic to pic code question ... |
Posted: Sun Apr 24, 2005 11:30 am |
|
|
Hello CCS community:
I am new to programming pic micro-controllers and am having trouble trying to get two pic16F87/88s to communicate with each other. My seriaI communication with the PC is working fine (I get "g"s in the hyperterminal), but when I try to input from keyboard over serial line, type "g", I get nothing. I am posting two programs below. Does anyone see anything in my software code that is incorrect? Please let me know. Thanks. - J_D
Program 1:
//this is an example of use of "printf" function
//this a way for us to communicate with MCU
//NOTE: We will set up serial communication
//between PC and MCU using MAX232 transceiver chip
//Last Updated: Sun 01/30/2005
//Dima
#include <../../16F88.H> // tell the CCS compiler which chip we are using
#fuses INTRC, NOWDT, NOPROTECT, NOBROWNOUT, PUT, NOLVP, NOMCLR
//select internal oscillator, no watchdog timer, no code protection,
//disable brownout detection, enable power up timer
//disable low voltage programming mode, disable reset pin
#use standard_io(A) // allow for input-output on port A
#use standard_io(B) // allow for input-output on port B
#use delay(clock=8000000) // tell the compiler what speed clock you are using
#use rs232(baud=9600, xmit=PIN_B5, rcv=PIN_B2)
//set up communication lines, transmit on portB pin 5 and recieve on
portB pin two
//-------------------------------------------------
#define TEST_PIN PIN_A0
#define ONE_SEC 1000
#define ONEHALF_SEC 500
#define QUATER_SEC 250
//-------------------------------------------------
void main()
{
setup_oscillator(OSC_8MHZ | OSC_INTRC); //set up internal oscillator
to run at
//8 million clicks per second
while(TRUE) //loop forever
{
delay_ms(ONEHALF_SEC); // wait for 500 milliseconds
output_high(TEST_PIN);
printf("g");
delay_ms(QUATER_SEC);
output_low(TEST_PIN);
}
}
Program 2:
//this is an example of how we can read character
//input from keyboard over serial line
//NOTE: We will set up serial communication
//between PC and MCU using MAX232 transiver chip
//Last Updated: Sat 02/12/2005
//Dima
#include <16F88.H> // tell the CCS compiler which chip we are using
#fuses INTRC, NOWDT, NOPROTECT, NOBROWNOUT, PUT, NOLVP, NOMCLR
//select internal oscillator, no watchdog timer, no code protection,
//disable brownout detection, enable power up timer
//disable low voltage programming mode, disable reset pin
#use standard_io(A) // allow for input-output on port A
#use standard_io(B) // allow for input-output on port B
#use delay(clock=8000000) // tell the compiler what speed clock you are using
#use rs232(baud=9600, xmit=PIN_B5, rcv=PIN_B2, stream=FROMPIC_1)
#use rs232(baud=9600, xmit=PIN_B1, rcv=PIN_B0, stream=TO_PC)
//set up communication lines, transmit on portB pin 5 and recieve on
portB pin two
//NOTE: these correspond to hardware UART tx and rx pins
//-------------------------------------------------
#define TEST_PIN PIN_A0
#define TEST_INPUT PIN_A2
#define ONE_SEC 1000
#define ONEHALF_SEC 500
#define QUATER_SEC 250
//-------------------------------------------------
void main()
{
int a;
setup_oscillator(OSC_8MHZ|OSC_INTRC); //set up internal oscillator to run at
//8 million clicks per second
while(TRUE) //loop forever
{
a=fgetc(FROMPIC_1); //start looking for any character on serial
input line
//if ANY character is detected procede to the next statement
if(a=='g') //"g" key is pressed on the keyboard
{
fprintf(TO_PC,"Oh yeah, I found the g \n\r");
delay_ms(QUATER_SEC); //delay a bit before reading again
}
}
}
Thanks again for your help!
|
|