|
|
View previous topic :: View next topic |
Author |
Message |
Milo Guest
|
bad communication between pic and pc |
Posted: Thu Jun 12, 2003 1:47 pm |
|
|
Hey all, ... I am having a problem when connecting pic to pc. I can print messages to pc using printf statements, ... However, when it comes to putting characters from pc to pic, the whole thing crashes. Seems like whenever i try to use
getc(), everything goes down the drain. Here is a program I am trying to test, ... As you can see, program should work only when it receives lowercase l from pc, ... However, it works with any key pressed, ... Sometimes it even crashes and generates garbage, ... Most of the times it doesn't work at all, ... I am not using MAX232, therefore I used INVERT option in my #use rs232 directive, ... Also, my clock is external 20 MHz, ... The wave looks more like a sinusiod than square, ... Could this be a problem?, ... Anyway, here is the code, and if you have any sugggestions, help is always welcome, ...
#include <16F84A.h>
#use delay(clock=20000000)
#fuses HS,NOWDT
#use rs232(baud=9600,parity=N,xmit=PIN_B1,rcv=PIN_B2, INVERT)
void main()
{
byte answer;
//setup_counters(RTCC_EXT_L_TO_H,RTCC_DIV_2);
#use standard_io(A)
SET_TRIS_A(0x00); //ALL A PINS AS OUTPUTS
OUTPUT_LOW(pin_A0);
OUTPUT_LOW(pin_A1);
OUTPUT_LOW(pin_A2);
OUTPUT_LOW(pin_A3);
#use standard_io(B)
SET_TRIS_B(0x04); //B2 INPUT; B1 OUTPUT;
OUTPUT_B(pin_B1);
OUTPUT_LOW(pin_B0);
OUTPUT_LOW(pin_B3);
OUTPUT_LOW(pin_B4);
OUTPUT_LOW(pin_B5);
OUTPUT_LOW(pin_B6);
OUTPUT_LOW(pin_B7);
disable_interrupts(GLOBAL);
disable_interrupts(INT_RTCC);
disable_interrupts(INT_RB);
disable_interrupts(INT_EEPROM);
disable_interrupts(INT_EXT);
putc(13); //this is where the problem occurs
delay_ms(85);
do{
answer=getch();
}while (answer!=0x6c);
printf("Emergency!... Emergency!... Emergency!... \n");
putc(13);
}
___________________________
This message was ported from CCS's old forum
Original Post ID: 144515188 |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
Re: bad communication between pic and pc |
Posted: Thu Jun 12, 2003 2:17 pm |
|
|
Do you have a 10K resistor on Pin B2 ? If you're not using
a MAX232 chip, then you need the resistor.
:=#include <16F84A.h>
:=#use delay(clock=20000000)
:=#fuses HS,NOWDT
:=#use rs232(baud=9600,parity=N,xmit=PIN_B1,rcv=PIN_B2, INVERT)
:=
:=
:=void main()
:={
:= byte answer;
:=
:= //setup_counters(RTCC_EXT_L_TO_H,RTCC_DIV_2);
:=
:=
Standard I/O is the default. You don't have to specify it,
unless you're switching to fast_io at some other point
in the program.
:= #use standard_io(A)
:= SET_TRIS_A(0x00); //ALL A PINS AS OUTPUTS
:= OUTPUT_LOW(pin_A0);
:= OUTPUT_LOW(pin_A1);
:= OUTPUT_LOW(pin_A2);
:= OUTPUT_LOW(pin_A3);
:=
:=
:= #use standard_io(B)
:= SET_TRIS_B(0x04); //B2 INPUT; B1 OUTPUT;
:=
This next line is not correct. You're writing the value
for "pin_B1", which is 49 (0x31) to Port B. I doubt that
this is what you intended to do.
:= OUTPUT_B(pin_B1);
:=
:= OUTPUT_LOW(pin_B0);
:= OUTPUT_LOW(pin_B3);
:= OUTPUT_LOW(pin_B4);
:= OUTPUT_LOW(pin_B5);
:= OUTPUT_LOW(pin_B6);
:= OUTPUT_LOW(pin_B7);
:=
:=
These interrupts are disabled upon power-up.
You don't need to turn them off.
:= disable_interrupts(GLOBAL);
:= disable_interrupts(INT_RTCC);
:= disable_interrupts(INT_RB);
:= disable_interrupts(INT_EEPROM);
:= disable_interrupts(INT_EXT);
:=
:= putc(13); //this is where the problem occurs
:= delay_ms(85);
:=
:= do{
:= answer=getch();
:= }while (answer!=0x6c);
:=
:=
:=
:= printf("Emergency!... Emergency!... Emergency!... \n");
:= putc(13);
The PIC will go to sleep right here. Do you want that ?
If not, put this statement here:
while(1);
:=}
___________________________
This message was ported from CCS's old forum
Original Post ID: 144515191 |
|
|
Milo Guest
|
Re: bad communication between pic and pc |
Posted: Thu Jun 12, 2003 2:54 pm |
|
|
Thanx a lot man, ... The program works perfectly now, ... Milo
___________________________
This message was ported from CCS's old forum
Original Post ID: 144515192 |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|