First the design, then the problem solving, then the hardware, and now the software. I can get scholarships for less than this.
Basic program design
It makes sense to split the programming into two parts - the serial monitor/reader and the lights manager. The serial monitor needs to be running all the time, and the light manager (thanks to my shift registers) need only run when the lights' intensities change.
Serial monitor basics
The serial monitor must satisfy these requirements:
The continuous bit-shifting self-resynchronizing algorithm
I just love that name. Basically it's the fruit of my labor to come up with an algorithm that rejects noise and unrelated data. Basically it pretends the RX433 is putting out a stream of bits all the time, always shifting it into its Rcvbyte. Whenever it encounters a pulse that's not in time with what it expects, the algorithm resets itself to that pulse and readies itself again. Every time one of these bit-shifts is performed, the algorithm checks the Rcvbyte against the predefined character (the lowercase ASCII 'a') - if it's a match, the algorithm calls a more dedicated procedure, known as Hotinput. Take a look at the code:
bitshiftloop ;The bit-shifting algorithm
clrf Rcvbyte ;Clear the receive byte buffer
movf Radioport, W ;Read the radio pin
movwf Prevport ;Save it for future comparison
call Resettimer ;Reset the timer
bsl1
skiple TMR0, Serialbittime ;Skip next statement if not enough time has elapsed
call Savebit ;If the timer expired, save the bit
movf Radioport, W ;Get the current radio pin state
xorwf Prevport, F ;Compare it with the previous state
btfss Prevport, Radiopin ;Skip next if the pin has changed
goto bsl2 ;Skip over the bit-saving code
call Savebit ;Save the bit
call Delaypartbit ;Delay a portion of a bit
call Resettimer ;Reset the timer
bsl2
movf Radioport, W ;Read the radio pin again
movwf Prevport ;Save it for future reference
skipne Rcvbyte, Targetbyte ;Check for a match to our target byte
call Hotinput ;If it matches, begin receiving data
goto bsl1 ;Loop
There you have it - it's all pretty simple once you come up with it. The procedure Savebit actually saves the bit and resets the timer, in case you're wondering. The skiple and skipne are macros I defined that basically mean "skip next statement if x is less than or equal to y" and "skip next statement if x is not y" - I made similar ones named skipgt and skipeq for "greater than" and "equal to", respectively.
The LED brightness setting code
I used a common PWM algorithm with a little twist to synchronize it with the clock. Basically it adds the brightness to a special Accumulator variable. If the accumulator is greater than or equal to eight (the maximum brightness), the accumulator is reset and the pin is set high for that cycle. If it is not, the pin is set low. Either way, the pin stays that way until the next clock cycle. This is done for eight clock cycles.
Congratulations on getting this far.
On to Page 5 - Enough talk... I wanna do it!
Copyright © 2003 by Nathan True - wlcolor at natetrue.com