|
|
View previous topic :: View next topic |
Author |
Message |
capella
Joined: 07 Feb 2009 Posts: 38
|
rs232 controlling and 16f877 output problem |
Posted: Sat Feb 07, 2009 6:38 am |
|
|
Hello, my problem is that rs232 and pic16f877 communication problem. I want to give 16f877 rb0 or rb1 outputs from pc's keyboard. For example when I wanted to press keyboard, I want to take voltage that pic 16f877 from RB0 output.
Please help me...
source code
Code: | #include <16F877.h>
#device adc=8
#FUSES NOWDT //No Watch Dog Timer
#FUSES XT //Crystal osc <= 4mhz
#FUSES NOPUT //No Power Up Timer
#FUSES PROTECT //Code protected from reads
#FUSES NOBROWNOUT //No brownout reset
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOCPD //No EE protection
#FUSES NOWRT //Program memory not write protected
#FUSES NODEBUG //No Debug mode for ICD
#use delay(clock=4000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)
#byte port_b = 6
void main()
{
int data;
set_tris_b( 0x00 );
output_B(0x00);//portb çıkış
printf("calisiyor…\n\r");
while (TRUE)
{
data = getch();
port_b = data; //gönderilen sayıyı portb de göster
if(data=="1") output_high(PIN_B0);
if(data=="2") output_high(PIN_B1);
if(data=="3") output_high(PIN_B2);
if(data=="4") output_high(PIN_B3);
if(data=="5") output_high(PIN_B4);
if(data=="6") output_high(PIN_B5);
if(data=="7") output_high(PIN_B6);
}
} |
|
|
|
Ttelmah Guest
|
|
Posted: Sat Feb 07, 2009 10:30 am |
|
|
Before doing anything else, add series resistors between the PIC pins, and the LEDs. At present, every port Bpin that goes high, will result in overloading the pin (and probably the LED)...
Then, do you want to output the bit pattern comming from the serial as a whole to port B?. If so the retain the line "port_b = data;". Otherwise get rid of this.
In any event, you don't want this line, and the separate lines accessing the port for the different values as well.
You might want to translate the 'comment' on this line.
Best Wishes |
|
|
nicotec
Joined: 07 Nov 2008 Posts: 60
|
|
Posted: Sat Feb 07, 2009 11:50 am |
|
|
Hi, to avoid too external capacitor I suggest You to use MAX233 which need only 10uF capaciton on between VDD and ground.
Regards |
|
|
capella
Joined: 07 Feb 2009 Posts: 38
|
|
Posted: Sat Feb 07, 2009 2:08 pm |
|
|
Hi, thanks for your answers.
Actually, my problem is that the code doesn't work. I am not good at pic c. My intent is to type a number 0-9 from my pc keyboard, and then one of led will be light. In more details, when I press 1 on the keyboard, the only 1st led will be on, and when it is 2, then only second led will be on.. and so on. On Proteus, I used virtual terminal as serial port.
Can you help me how to change or write the correct codes to make it work? |
|
|
|
|
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
|