00235
0000 00236 ORG 0x00
0000 0025 00237 MOVWF OSCCAL
00238
0001 0A31 00239 GOTO start
00240
00241
00242 ; **************************************************************
00243 ; Subroutines
00244 ;
00245
00246
00247 ; **************************************************************
0002 00248 send_char
00249
00250 ; Call send_char with an ASCII character code in W. This is a
00251 ; simple serial output routine which sends the character out
00252 ; serially on an output pin at 1200 baud, 8 data bits, no parity,
00253 ; 1 stop bit. Assume the PIC oscillator is running at 4MHz.
00254 ;
00255 ; The baud rate of 1200 baud was chosen as it will work with the
00256 ; 12C509 internal RC oscillator generating the timing. Higher
00257 ; baud rates require tighter timing tolerance, and will therefore
00258 ; require a crystal.
00259 ;
00260 ; Normally serial communication (RS232) requires a negative
00261 ; voltage between -5V to -15V to represent a ’1’, and a positive
00262 ; voltage between +5V and +15V to represent a ’0’. Most PC
00263 ; serial ports will switch at +/-3V, and in fact will often work
00264 ; with 0V and 5V, so it is possible to use a PIC I/O pin, set
00265 ; high for a logic ’0’ and low for a logic ’1’. A 1k resistor
00266 ; placed in series with the Tx line will limit the current, and
00267 ; This is probably acceptable for experimental purposes. For
00268 ; robustness, however, it may be desirable to include level shift
00269 ; IC, such as the MAX232A from Maxim. The invert_tx compilation
00270 ; option can be used to alter the sense of transmitted bits if
00271 ; necessary.
00272 ;
00273 ; At 1200 baud each bit cell is just over 833us in length. At
00274 ; power up the serial output line is set to its idle state (logic
00275 ; ’1’). At the start of transmission it is taken to logic ’0’
00276 ; for one bit time to generate the start bit. Next, the 8 bits
00277 ; of character data are shifted out, LSB first, by rolling them
00278 ; down into the carry. The program sets or clears the serial
00279 ; line pin according to whether the carry represents a logic ’0’
00280 ; or ’1’. Finally the line is held at logic ’1’ for at least one
00281 ; bit time for the stop bit. The line then rests at this state
00282 ; (idle) until it is time to send the next byte
00283 ;
00284 ; Bit cell timing is done by counting clock cycles: 1 instruction
00285 ; is 1us, jumps and skips are 2us.
00286
0002 002B 00287 MOVWF char_buf ; Store the character code (in W)
00288 ; to character buffer
00289
0003 0C0A 00290 MOVLW .10 ; Set the number of bits (including
0004 0029 00291 MOVWF count ; start and stop bits) in count
00292
0000 00236 ORG 0x00
0000 0025 00237 MOVWF OSCCAL
00238
0001 0A31 00239 GOTO start
00240
00241
00242 ; **************************************************************
00243 ; Subroutines
00244 ;
00245
00246
00247 ; **************************************************************
0002 00248 send_char
00249
00250 ; Call send_char with an ASCII character code in W. This is a
00251 ; simple serial output routine which sends the character out
00252 ; serially on an output pin at 1200 baud, 8 data bits, no parity,
00253 ; 1 stop bit. Assume the PIC oscillator is running at 4MHz.
00254 ;
00255 ; The baud rate of 1200 baud was chosen as it will work with the
00256 ; 12C509 internal RC oscillator generating the timing. Higher
00257 ; baud rates require tighter timing tolerance, and will therefore
00258 ; require a crystal.
00259 ;
00260 ; Normally serial communication (RS232) requires a negative
00261 ; voltage between -5V to -15V to represent a ’1’, and a positive
00262 ; voltage between +5V and +15V to represent a ’0’. Most PC
00263 ; serial ports will switch at +/-3V, and in fact will often work
00264 ; with 0V and 5V, so it is possible to use a PIC I/O pin, set
00265 ; high for a logic ’0’ and low for a logic ’1’. A 1k resistor
00266 ; placed in series with the Tx line will limit the current, and
00267 ; This is probably acceptable for experimental purposes. For
00268 ; robustness, however, it may be desirable to include level shift
00269 ; IC, such as the MAX232A from Maxim. The invert_tx compilation
00270 ; option can be used to alter the sense of transmitted bits if
00271 ; necessary.
00272 ;
00273 ; At 1200 baud each bit cell is just over 833us in length. At
00274 ; power up the serial output line is set to its idle state (logic
00275 ; ’1’). At the start of transmission it is taken to logic ’0’
00276 ; for one bit time to generate the start bit. Next, the 8 bits
00277 ; of character data are shifted out, LSB first, by rolling them
00278 ; down into the carry. The program sets or clears the serial
00279 ; line pin according to whether the carry represents a logic ’0’
00280 ; or ’1’. Finally the line is held at logic ’1’ for at least one
00281 ; bit time for the stop bit. The line then rests at this state
00282 ; (idle) until it is time to send the next byte
00283 ;
00284 ; Bit cell timing is done by counting clock cycles: 1 instruction
00285 ; is 1us, jumps and skips are 2us.
00286
0002 002B 00287 MOVWF char_buf ; Store the character code (in W)
00288 ; to character buffer
00289
0003 0C0A 00290 MOVLW .10 ; Set the number of bits (including
0004 0029 00291 MOVWF count ; start and stop bits) in count
00292