; ; transmit.asm ; ; Justice Unlimited Gadget Microcode ; (C) 2004 Nathan (Acorn) Pooley ; ; transmit.asm ; ;@DOC@ Main gadget source file - includes all other files ; include <def_16628.inc> RADIX DEC ; ; CONFIGURATION WORD ; ; 4,1,0 = 010 HS crystal osc ; 2 = 0 watchdog disabled ; 3 = 0 power up timer enabled ; 5 = 0 MCLR disabled (no RA5) ; 6 = 0 brown out disabled ; 7 = 0 LVP disabled ; 8 = 1 data protection off ; 9 = 1 reserved ; 13,12,11,10 = 1111 code protection off ; 15,14 = 00 unused ; __CONFIG 0x3f02 #define SIM 0 ; 1 = using simulator ; 0 = using hardware #define DO_TEST 0 ; ; NOTE: 20MHz ; #define DEBUG 1 #define DEBUG_BITS 1 #define REPORT_ERRORS 1 #define SIMULATE_SERIAL SIM ; disable serial #define TEST_INPUT 0 ; just run NOPs when input occurs #define CHECK_TABLES 1 ; ensure table does not cross ; page boundaries #define SIMULATE_INPUT SIM ; use rb0, rb1, rb2 to sim input LED_HPERIOD0 equ 256-55 ; initial on time LED_HPERIODA equ 256-51 ; regular on time LED_HPERIODB equ 256-52 ; regular off time ; period = 125 instructions ; 62+63 = 125 ; (plus1 is because both are 0-based) ; freq = 40kHz ;############################################ ;############### VARIABLES ################## ;############################################ #define b_led PORTA,0 ; OUT: turn LED on=0 off=1 #define b_ir_state PORTA,1 ; OUT: ir state send=0 off=1 #define b_mode_toggle PORTA,2 ; IN: toggle mode if set TRISA_VAL equ 0xfc ; bit 0,1 are output TRISB_VAL equ 0xff ; all input #define b_led_state v_bits0,0 v_bits0 equ 0x20 ; example register def v_delay1 equ 0x21 ; delay arguments v_delay2 equ 0x22 v_dcnt1 equ 0x23 ; delay counter v_dcnt2 equ 0x24 ;############################################ ;############### MACROS ##################### ;############################################ ;############################################ ;############### VECTORS #################### ;############################################ ; ; RESET ; org 0x0000 #if DO_TEST goto test_mode #endif goto init ; ; interrupt vector ; org 0x0004 ;############################################ ;############### TIMER0 INTERRUPT ########### ;############################################ t0_isr: bcf b_t0if btfss b_led_state goto t0_was_on t0_was_off: bcf b_led_state ; led state bsf b_led ; turn LED on movlw LED_HPERIODA ; how long to leave on movwf TMR0 retfie t0_was_on: bcf b_led ; turn LED off bsf b_led_state ; led state movlw LED_HPERIODB ; how long to leave off movwf TMR0 retfie ;############################################ ;############### IR ON/OFF ################## ;############################################ ir_on: movlw LED_HPERIOD0 movwf TMR0 bsf b_led ; turn LED on bcf b_led_state ; led state bcf b_ir_state ; debug output bcf b_t0if bsf b_t0ie ; enable interrupt return ir_off: bcf b_t0ie ; disable interrupt bcf b_led ; LED off bsf b_led_state bsf b_ir_state ; debug output return ;############################################ ;############### INIT ####################### ;############################################ init: ; ; access bank 0 (assumed by isr) ; bcf b_rp1 bcf b_rp0 ; ; disable interrupts ; clrf INTCON ; disable all interrupts clrf PIR1 ; turn off periferal int flags bsf b_peie ; enable periferal interrupts bsf b_rp0 ; PIE in bank 1 CLRF PIE1 ; disable periferal interrupts bcf b_rp0 ; ; setup PORTS & timers ; movlw 0x07 movwf CMCON ; portA is digital I/O movlw 0xff ; PORTA,B all bits set movwf PORTA movwf PORTB ; ; which port pins are inputs? ; bsf b_rp0 ; TRISA,B in bank 1 movlw TRISB_VAL movwf TRISB movlw TRISA_VAL movwf TRISA bcf b_rp0 ; ; setup timers ; clrf T2CON clrf T1CON ; ; setup timer0 ; bcf b_t0ie ; interrupt disabled bsf b_rp0 ; following are in bank1 bcf b_t0cs ; timer (not counter) bsf b_t0psa ; do NOT use prescaler bcf b_t0ps0 ; prescale = 0 bcf b_t0ps1 bcf b_t0ps2 bcf b_rp0 ; ; enable interrupts ; bsf b_gie ;############################################ ;############### MAIN ####################### ;############################################ OFF_TIME1 equ 215 ; 215,5 = 650 usec OFF_TIME2 equ 5 main: call send_on_bit call send_off_bit call send_off_bit call send_off_bit call send_off_bit call send_off_bit #if 0 call send_on_bit call send_on_bit call send_on_bit call send_on_bit call send_on_bit call send_off_bit call send_off_bit call send_off_bit call send_off_bit call send_off_bit #else call send_off_bit call send_off_bit call send_off_bit call send_off_bit call send_off_bit call send_off_bit call send_off_bit call send_off_bit call send_off_bit call send_off_bit call send_off_bit call send_off_bit call send_off_bit call send_off_bit call send_off_bit call send_off_bit call send_off_bit call send_off_bit call send_off_bit call send_off_bit call send_off_bit call send_off_bit call send_off_bit call send_off_bit call send_off_bit call send_off_bit call send_off_bit call send_off_bit call send_off_bit call send_off_bit call send_off_bit call send_off_bit call send_off_bit call send_off_bit call send_off_bit call send_off_bit call send_off_bit call send_off_bit call send_off_bit call send_off_bit call send_off_bit call send_off_bit call send_off_bit call send_off_bit call send_off_bit call send_off_bit call send_off_bit call send_off_bit call send_off_bit call send_off_bit call send_off_bit call send_off_bit call send_off_bit call send_off_bit call send_off_bit call send_off_bit call send_off_bit call send_off_bit call send_off_bit call send_off_bit call send_off_bit call send_off_bit call send_off_bit call send_off_bit call send_off_bit call send_off_bit call send_off_bit call send_off_bit call send_off_bit call send_off_bit #endif goto main ;############################################ ;############### SEND BIT ################### ;############################################ OFF_TIME1 equ 215 ; 215,5 = 650 usec OFF_TIME2 equ 5 send_off_bit: call send_off_pulse goto send_bit_common send_on_bit: call send_on_pulse send_bit_common: movlw OFF_TIME1 movwf v_delay1 movlw OFF_TIME2 movwf v_delay2 call delay return ;############################################ ;############### SEND PULSE ################# ;############################################ ON_TIME1 equ 193 ; 193,3 = 350 usec ON_TIME2 equ 3 send_on_pulse: call ir_on send_off_pulse: movlw ON_TIME1 movwf v_delay1 movlw ON_TIME2 movwf v_delay2 call delay goto ir_off ;############################################ ;############### DELAY ###################### ;############################################ ; ; delay for ; cycles: 4 + d2 * (4 + (3 * d1)) ; usec = cycles * 0.2 usec/cycle ; (inlcuding call and return) ; ; v_delay1 = d1 ; v_delay2 = d2 delay: movf v_delay1,w ; 4 + d2 * (4 + (3 * d1)) movwf v_dcnt1 delay_loop1: movf v_delay2,w ; 4 + 3*d1 cyc/loop2 movwf v_dcnt2 delay_loop2: decfsz v_dcnt2,f ; 3 cyc/loop2 goto delay_loop2 decfsz v_dcnt1,f goto delay_loop1 return ;############################################ ;############### TEST ####################### ;############################################ test_mode: ; ; access bank 0 (assumed by isr) ; bcf b_rp1 bcf b_rp0 ; ; disable interrupts ; clrf INTCON ; disable all interrupts clrf PIR1 ; turn off periferal int flags bsf b_peie ; enable periferal interrupts bsf b_rp0 ; PIE in bank 1 CLRF PIE1 ; disable periferal interrupts bcf b_rp0 ; ; setup PORTS & timers ; movlw 0x07 movwf CMCON ; portA is digital I/O movlw 0xff ; PORTA,B all bits set movwf PORTA movwf PORTB bsf b_rp0 ; TRISA,B in bank 1 movlw 0 movwf TRISB ; all PORTB is input movwf TRISA ; PORTA has some in, some out bcf b_rp0 ; ; setup timers ; clrf T2CON clrf T1CON ; ; setup timer0 ; bcf b_t0ie ; interrupt disabled bsf b_rp0 ; following are in bank1 bcf b_t0cs ; timer (not counter) bsf b_t0psa ; do NOT use prescaler bcf b_t0ps0 ; prescale = 0 bcf b_t0ps1 bcf b_t0ps2 bcf b_rp0 ; ; enable interrupts ; bsf b_gie ; SET ALL: works for all except A4,A5 ; CLEAR ALL: works for all except A5 test_loop: movlw 0x00 movwf PORTA movwf PORTB goto test_loop ;############################################ ;############### END ######################## ;############################################ end |
This file Copyright (C) 2004 by Nathan (Acorn) Pooley
Go to Bat Blinker Development page
Go to Bat Blinker page
Go to JU Gadgets page
Go to Justice Unlimited homepage
Go to Acorn's personal webpage
Contact Acorn
See comments from others
Post your own comments
File created by do_doc at Wed Aug 4 21:07:00 2004