In message <16E6E1E1227@novell6.bham.ac.uk>, AI BEVAN writes >Does anyone know how to get this small chip to communicate with a >serial port. All I want is a program that will send a simple >character, like a 'a', through the serial port. I want this so I can >build some kind of serial test for visual basic. >If anyone knows can they please tell me, or can they give me an >address of someone who will be able to help. > >I believe that I will have to connect a chip like a MAX232 between >the computer and the microchip. > >Many thanks >A Bevan Aib750@Bham.ac.uk This might help. I don't know where I got it from, and am not sure if it works. config 0fdh ;; WDT Enabled, XT Oscillator ; include 16c84reg.inc include 16c84.inc sio_port equ porta sio_tx_bit equ porta.0 sio_rx_bit equ porta.1 sio_tris_val equ 0feh orgdata ram_base org program_start goto boot_up ;; The following provides an interrupt which is called at regular ;; intervals (3 * baud rate). This number has been chosen as it is ;; the minimum reliable frequency required for serial IO support. ;; ;; This file requires the following value to be defined ;; timer0_div_value = 256 - ((xtal_freq/(3 * 4*baud*prescaler_rate)) ;; and the next timer0 load. ;; baud = 2400 ;; xtal = 4000000 timer0_div_value equ 117 ; 256 - (4000000/(3* 4 * 2400* 1)) = 256 - 139 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Interrupt service routine ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; org interrupt_start w_save rb ; Place to save W status_save rb ; Place to save Status ; magic code to save w and status so that they don't get corrupted ; by the interrupt service routine movwf w_save movf status,w movwf status_save ; check if it's the timer interrupt btfss t0if goto skip_timer_isr ; no it wasn't ; get here at 3 * baud rate bcf t0if ; clear interrupt flag ; load timer0 with next divisor movlw timer0_div_value addwf tmr0,f ; NB add so that latency is not lost call sio_service_handler skip_timer_isr ; restore w and status registers before returning... movf status_save,w movwf status swapf w_save,f swapf w_save,w retfie ;; end of interrupt service routine ;; init_timer initialises the timer stuff init_timer movlw 0dfh ; use internal clock for TMR0 option ; load timer0 with divisor movlw timer0_div_value movwf tmr0 bcf t0if ; clear interrupt flag ; enable timer0 interrupt bsf t0ie ; enable timer0 interrupts bsf gie ; enable global interrupts return ;; variables: ;; sio_state: 6..0 rx/tx state machine state ;; 7 = 1 if tx, = 0 if rx ;; sio_byte: byte being received or transmitted ;; bitcnt: bit count for tx/rx, also holds tx_flag. wait_start_period equ 1 bit_period equ 3 start_skip_period equ 4 sio_byte rb bitcnt rb tx_flag equ bitcnt.7 samplecnt rb ;; call sio_init to initialise the sio routines sio_init movlw sio_tris_val ; set port directions tris sio_port goto init_timer ; now initialise the timer ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; execute tx_byte with the byte in sio_byte to start a byte transmission ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; tx_byte movlw 9 ; 8 data + 1 stop bit on tx movwf bitcnt bcf sio_tx_bit ; output start bit bsf tx_flag movlw bit_period goto ld_samplecnt_continue ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; sio_service_handler is called at 3 * baud rate ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; sio_service_handler decfsz samplecnt,f goto continue sio_service ; if we are receiving, goto rx_service btfss tx_flag goto rx_service tx_service movf bitcnt,w andlw 0fh ; strip off tx_flag btfsc z goto tx_byte_complete decf bitcnt,f ; output next bit btfsc sio_byte.0 bsf sio_tx_bit btfss sio_byte.0 bcf sio_tx_bit ; shift bits, move a 1 into bit 7 for stop bit rrf sio_byte,f bsf sio_byte.7 ; load up for next sample period and continue movlw bit_period goto ld_samplecnt_continue ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; execute rx_byte to initiate a byte reception. ;; When the byte has been recieved, exec continues at rx_byte_complete ;; with the received byte in sio_byte ;; ...-+ : : : : : : : : :---- ;; +----: : : : : : : : : ;; State 9 8 7 6 5 4 3 2 1 ;; ;; State 9 : Waiting for start bit transition ;; State 8 : Waiting to sample D0 ;; State 7 : Waiting to sample D1 ;; State 6 : Waiting to sample D2 ;; State 5 : Waiting to sample D3 ;; State 4 : Waiting to sample D4 ;; State 3 : Waiting to sample D5 ;; State 2 : Waiting to sample D6 ;; State 1 : Waiting to sample D7 ;; State 0 : Waiting to get into stop bit area. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; rx_byte movlw 9 movwf bitcnt bcf tx_flag ; then executes the code in rx_service ... ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; rx_service gets executed to process an interrupt during ;; ;; a byte receive. ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; rx_service movf bitcnt,w ; check if all bits have been received btfsc z goto rx_byte_complete ;check if waiting for start bit movlw 9 xorwf bitcnt,w btfss z goto not_start ; we are waiting for the start bit btfsc sio_rx_bit goto start_not_found ; start bit has been detected, so skip sampling for t*4/3. decf bitcnt,f clrf sio_byte movlw start_skip_period goto ld_samplecnt_continue start_not_found ; start bit not yet found, wait for t/3 and sample again. movlw wait_start_period goto ld_samplecnt_continue not_start ; receiving data bit, then wait for bit_period for the next sample rrf sio_byte,f ; shift data bcf sio_byte.7 ; clear MSbit btfsc sio_rx_bit ; sample the data pin bsf sio_byte.7 ; set MSbit if pin low decf bitcnt,f movlw bit_period ; set the next delay ld_samplecnt_continue movwf samplecnt continue return ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; tx_byte_complete is executed when a byte has been transmitted ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; tx_byte_complete goto rx_byte ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; rx_byte_complete is executed when a byte has been received ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; rx_byte_complete incf sio_byte,f goto tx_byte ;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Main program starts here ;;;;;;;;;;;;;;;;;;;;;;;;;;;; boot_up call sio_init call rx_byte loop_forever clrwdt goto loop_forever -- Leon Heller: leon@lfheller.demon.co.uk http://www.lfheller.demon.co.uk Amateur Radio Callsign G1HSM Tel: +44 (0) 118 947 1424 See http://www.lfheller.demon.co.uk/rcm.htm for details of a low-cost reconfigurable computing module using the XC6216 FPGA