0
\$\begingroup\$

The micro is an AT89C4051. It allows two timers and a serial port interrupt.

Currently, I set things up so that if any kind of data is received on the serial port, it just is loaded into memory by the serial routine (not shown) and the timer is called right away. However, when no data is received within a certain time limit (1mS for example here), then the end of data stream is assumed and if a packet is valid, it gets processed.

Here's the code I have so far:

timer0_interrupt:
  ;Reset default delay to 1mS
  mov TH0,#0FDh
  jbc GOTANYBYTE,notmo
    ;No byte was received within 1mS
    ;So reset receive pointer
    mov SIR0,#SRX 
    ;And if whats received so far is a packet, then process it
    enddopacket:
    jbc SERPACKET,dopacket 
    djnz TIMEOUT,notmox
      ;Timed out. Proceed to next client
      mov TIMEOUT,#MAXUNITS
    notmox:
  notmo:
reti

dopacket:
  ;here an entire packet (of 10 bytes) is received 
  ;so process it right away
ljmp enddopacket

What I want to do is assign each client a fixed amount of time to send their packet (yes, the serial is via wireless). I want the time to be exactly the same for each client regardless of how much or the quality of the packet that goes through.

Currently I'm using timer 0 and TIMEOUT variable to sort-of achieve this. This is because the timer interrupt is executed anywhere from about 170uS (the time it takes for a byte to come in at 56kbps on the serial line) to about 1mS and therefore my timing can be thrown off.

My serial interrupt depends on timer 1 because data is at 56K on a 22.1184Mhz crystal and I can't achieve the same baud using other serial modes that don't require timer 1.

Is there a possibility that I can run this routine under timer 1 instead of timer 0 and use timer 0 as the actual timeout timer, or will timer 1 conflict with the serial port interrupt execution time so much that one of those interrupt routines can't run properly?

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.