|
|
View previous topic :: View next topic |
Author |
Message |
lgeorge123
Joined: 05 Dec 2004 Posts: 31
|
rs232 soft uart |
Posted: Tue Dec 28, 2004 9:14 am |
|
|
here I have my program using 16f877 to receive data from pc,once i
write down a ASCII B,a ASCII U is return, I tries many times but unsuccessfully.
in the main loop,one point is be minded that no while(1) should be used.
#include <16f877.H>
#fuses HS,NOWDT,NOPROTECT,NOLVP,BROWNOUT
#use delay(clock=12000000)
#use rs232(baud=9600, xmit=PIN_A5, rcv=PIN_A4,FORCE_SW,errors)
#byte porta = 5
#byte portb = 6
#byte portc = 7
#byte portd = 8
#byte porte = 9
char byte_read;
#int_rda
serial_isr(){
byte_read=getc();}
void main()
{
enable_interrupts(global);
enable_interrupts(int_rda);
setup_adc(no_analogs);
set_tris_a(0x00);
set_tris_b(0x00);
set_tris_c(0x00);
set_tris_d(0x00);
set_tris_e(0x00);
porta=0;
portb=0;
portc=0;
portd=0;
porte=0;
if (byte_read=='B')
{
putc('U');
byte_read=0;
}
} |
|
|
SherpaDoug
Joined: 07 Sep 2003 Posts: 1640 Location: Cape Cod Mass USA
|
|
Posted: Tue Dec 28, 2004 9:35 am |
|
|
I don't think the software UART can use interrupts. Try stripping out the interupt stuff and just write a program the blinks a LED when it receives any serial character. Then make it blink when it receives a 'B'. Then write one that sends 'U'. Then one that sends 'U' when it receives 'B'.
For interrupts you need to use the hardware UART. _________________ The search for better is endless. Instead simply find very good and get the job done. |
|
|
rwyoung
Joined: 12 Nov 2003 Posts: 563 Location: Lawrence, KS USA
|
|
Posted: Tue Dec 28, 2004 10:38 am |
|
|
It is possible to make a soft UART using interrupts if you use the interrupt on change/edge of RB0. But only for receiving. The "start" bit transition triggers the interrupt. Never tried it myself but I do remember reading about it here.
You can find more information using the forum's "search" feature. _________________ Rob Young
The Screw-Up Fairy may just visit you but he has crashed on my couch for the last month! |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Tue Dec 28, 2004 10:39 am |
|
|
Quote: | I don't think the software UART can use interrupts. | Affirmative, no support for interrupts by the software UART.
Quote: | It is possible to make a soft UART using interrupts if you use the interrupt on change/edge of RB0. | This is an option, but there are a lot of gotcha's with this one. It might be way too difficult for what lgeorge123 tries to achieve. For example if an half-duplex protocol is used the software UART is still a good option.
I'm a bit worried about the set_tris_a(0x00) command, this sets all pins on port A as outputs. This might work out OK, but as soon as you would add the '#use fast_io' directive things would definately go wrong. Please configure the I/O pins according to your connected hardware, e.g. set_tris_a(0x10).
Rewrite your program according to the recommendations of Sherpadoug |
|
|
lgeorge123
Joined: 05 Dec 2004 Posts: 31
|
soft rs232 |
Posted: Tue Dec 28, 2004 11:20 am |
|
|
actually I have a function,inside it a getchar() function is working,so it is
waiting user to input the data via visual basic program.could somebody give me any suggestion????????
#include <16f877.H>
#fuses HS,NOWDT,NOPROTECT,NOLVP,BROWNOUT
#use delay(clock=12000000)
#use rs232(baud=9600, xmit=PIN_A5, rcv=PIN_A4,force_sw,errors)
#byte porta = 5
#byte portb = 6
#byte portc = 7
#byte portd = 8
#byte porte = 9
int erase();
int program_chip();
char data_read;
int pass,pass1;
//portb=data,portc=a0-a7,portd=a8-a15,porte=a16-a18
//********************************************************************
void main()
{ setup_adc(no_analogs);
set_tris_a(0b0010000);
set_tris_b(0);
set_tris_c(0);
set_tris_d(0);
set_tris_e(0);
porta=0;
portb=0;
portc=0;
portd=0;
porte=0;
pass=0;
pass1=0;
pass= erase();
while(1){
if ((pass==1)||(pass1==1))
{ porta=0x06;
pass1=program_chip();
if (pass1==1)
porta=0x05; //pass
else
porta=0x07; //fail
}
else
porta=0x07;}
}//main
int program_chip()
{ char byte_read,byte_read1;
long index1,index2,index3;
index1=0;
index2=0;
index3=0;
pass1=0;
byte_read=0;
for(index1=0;index1<=0xff;index1++)
for(index2=0;index2<=0xff;index2++)
for(index3=0;index3<=0x07;index3++)
{
porta=0x01;
portc=index1;
portd=index2;
porte=index3;
byte_read=getchar(); //this is the place to waiting for data
if(byte_read!='!'){
set_tris_b(0x00);
portb=byte_read;
putc('M');
delay_us(100);
porta=0x02;
;;;;
;;;;;; |
|
|
|
|
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
|