PDA

View Full Version : On Interrupt



elektroline
- 6th November 2006, 18:53
Hi all,

i m writing a moving message display code... all things good now. but i need help a on interrupt send data from pc.. and write data 24c64


mainprogram:
.
.
.
interrupt rutine----> goto pclink
( help me for here)

goto mainprogram

--------------------------


PCtalk:
'start communicating with PC by sending acknowledge bit
j = 0 : pause 100 :

SERIN SERIALIN,N2400,["@"],bilgi 'wait for char. @ from the PC and store second @ in char...
getserial: 'start receiving serial data
Serin SERIALIN,N2400,bilgi 'receive at 9600bps and store in variable char
I2CWRITE SDA,SCL,$A0,j,[bilgi] 'write each received character to the memory, starting at 0

if bilgi = EOM then 'check to see if incoming character is EOM
Goto start 'go back to the very beginning of program to reset everything
endif 'end checking if character is EOM
j = j + 1 'increment pointer that points to the next memory location
goto getserial 'if incoming character was not EOM, return for more chars.

mister_e
- 6th November 2006, 23:50
it will help if we know what is the interrupt source... Usart, A/D converter, CCP, Timer, UFOs

Archangel
- 7th November 2006, 04:18
Serin SERIALIN,N2400,bilgi 'receive at 9600bps and store in variable char


N2400 = 2400 Baud Inverted

T9600 = 9600 True
N9600 = 9600 Inverted

elektroline
- 7th November 2006, 08:39
Hi ,

Mister_e;

interrupt ll be for usart.....

My code is godd running. but i want to send data from pc and when send will data from pc goto serin routine and write eprom


Joe S. ;

i m using 18f452
and 10 MHz quartz. and config is hs_pll ( 10 x 4 = 40 mHz )
so baud= 2400 x 4 = 9600 ( i hope :) )

mister_e
- 7th November 2006, 13:56
So your PIC have a Hardware USART, use it and use it's interrupts.

Use HSERIN instead of SERIN as it use the PIC Usart.

Maybe the following may help.
http://www.picbasic.co.uk/forum/showpost.php?p=8601&postcount=11

You just need to set you USART register for the Right baudrate
something like


RCSTA = $90 ' Enable serial port & continuous receive
TXSTA = $20 ' Enable transmit, BRGH = 0
SPBRG = 64 ' 9600 Baud @ 0.16%


OR


DEFINE HSER_RCSTA 90h ' Enable serial port & continuous receive
DEFINE HSER_TXSTA 20h ' Enable transmit, BRGH = 0
DEFINE HSER_SPBRG 64 ' 9600 Baud @ 0.16%
DEFINE HSER_CLROERR 1 ' Clear overflow automatically

elektroline
- 20th November 2006, 19:08
Hi, i write this codes but... i think interrupt is not working and data is not send from pc to pic eprom..





DEFINE HSER_RCSTA 90h
DEFINE HSER_SPBRG 64
DEFINE HSER_CLROERR 1
RCIF VAR PIR1.5
EOM con ""
bilgi var byte
b var byte
start:
if RCIF then ' incomming data?
HSERIN [bilgi]
if bilgi= "@" then
goto pctalk
else
goto start
endif
endif
....
....
... other codes
....
....


pctalk:
getserial:
HSERIN [bilgi]
write b, bilgi

if bilgi = EOM then
Goto start
endif
B = b + 1
goto getserial

Melanie
- 21st November 2006, 08:55
Consider...

HSERIN [bilgi]

... at 9600 baud means you're sending 9600 bits in a second... for arguments sake, say it takes 10 bits for one byte (with start and stop bits), so it takes less than 1mS per byte to receive...

And now...

write b, bilgi

...takes 10mS to write to EEPROM...

So for every ONE byte you save to EEPROM, using your code/method at only 9600 baud will ensure you lose the following 10/12 bytes of incoming data. Can you now see it's not so straightforward to receive RS-232 and write it to EEPROM... as you have to make sure that when you write to your EEPROM you're still going to grab any incoming data that may be arriving at the same time.