; copyright (c) 1995 A.Critchley - G3SXC #include "pic16c84.h" ;define ram linehi equ 10h linelo equ 11h ;current line trighi equ 12h triglo equ 13h ;trigger point lastb equ 14h oldb equ 15h ;copy of portb keepw equ 16h keeps equ 17h ;save regs for irq digit0 equ 18h digit1 equ 19h digit2 equ 1ah digit3 equ 1bh ;led digit stores addhi equ 1ch addmd equ 1dh addlo equ 1eh ;actual line in bcd count equ 1fh ;bit counter temp equ 20h icount equ 21h ;line delay counter flags equ 25h ;misc flags triger equ 0 udled equ 1 odd equ 2 ;porta allocations ldata equ 2 ;led data lclock equ 3 ;led clock ;portb allocations ;inputs lsync equ 0 ;mixed sync input fsync equ 1 ;odd/even input bright equ 2 ;brightup pulse level equ 3 ;chopper level strobe equ 4 ;chopper strobe output equ 7 ;trigger out maxl equ 624 ;max line count ofset equ 3 ;because were late segment byte at:0 'code' reset: nop clrwdt clrf intcon goto start irq: movwf keepw movf status,w movwf keeps btfsc intcon,intf ;not irq goto newlin ;else newtrigger bsf flags,udled movf lastb,w movwf oldb movf portb,w movwf lastb bcf intcon,rbif ;clr portb changed flag xorwf oldb,w ;find changed andwf lastb,w ;keep hi bits andlw 10h ;strobe bit btfsc status,z goto reload ;not lo>hi transition btfsc lastb,level goto down ;decrement counter ;increment counter incf triglo btfss status,z goto chktop incf trighi chktop: movlw high maxl subwf trighi,w btfss status,z goto reload ;<512 movf triglo,w sublw low maxl btfsc status,c goto reload ;<=maxl clrf trighi clrf triglo goto reload ;decrement counter down: decf triglo incf triglo,w btfss status,z ;was 0ff goto reload decf trighi incf trighi,w btfss status,z goto reload ;else we have 0ffff movlw high maxl movwf trighi movlw low maxl movwf triglo goto reload newlin: btfsc flags,triger bsf portb,bright ;start brightup pulse bcf flags,triger bsf portb,output ;inverted btfsc portb,fsync goto qset btfss flags,odd goto inclin ;no change bcf flags,odd goto inclin qset: btfsc flags,odd goto inclin ;no change bsf flags,odd clrf linehi clrf linelo ;start of new frame goto compar inclin: incf linelo btfsc status,z incf linehi compar: movf linelo,w subwf triglo,w btfss status,z goto endlin movf linehi,w subwf trighi,w btfsc status,z bsf flags,triger endlin: movlw 8 movwf icount lindel: decfsz icount goto lindel ;past equalizing or fsync pulse btfsc flags,triger bcf portb,output ;gate with mixed sync bcf portb,bright bcf intcon,intf ;clr irq flag reload: movf keeps,w movwf status movf keepw,w bcf status,z btfsc keeps,z bsf status,z retfie start: movlw 00h ;int on falling edge option movwf porta movwf portb movlw 0f3h tris porta ;all in movlw 1bh tris portb ;b0,1,3,4 in,b2,5-7 out clrf portb movf portb,w movwf lastb clrf trighi clrf triglo bsf intcon,gie ;global int enable bsf intcon,inte ;enable int pin bsf intcon,rbie ;enable portb changed interrupt main: call sndled goto main ;subroutines ;convert trigger value to bcd in addhi-addlo cvbcd: movf trighi,w btfss status,z ;0 goto try1 clrf addhi clrf addmd clrf addlo goto div10 try1: decf trighi,w btfss status,z ;256 goto l512 movlw 2 movwf addhi movlw 5 movwf addmd movlw 6 movwf addlo goto div10 l512: movlw 5 movwf addhi movlw 1 movwf addmd movlw 2 movwf addlo div10: movf triglo,w movwf temp divl: movlw 10 subwf temp,w btfss status,c ;>9 goto units movwf temp ;-10 call incmd goto divl units: movf temp,w ;add in remaining units, also used to add offset addun: addwf addlo movlw 10 subwf addlo,w btfss status,c ;>9 goto adend movwf addlo ;-10 incmd: incf addmd movlw 10 subwf addmd,w btfss status,c ;>9 goto adend movwf addmd incf addhi adend: retlw 00 ;send trigger value to led sndled: call cvbcd ;get point in bcd movlw ofset call addun ;add offset for delay ;offset may make value >625, check and round as required movlw 6 subwf addhi,w btfss status,z goto send ;<600 movlw 2 subwf addmd,w btfss status,z goto send ;<620 movf addlo,w sublw 5 btfsc status,c goto send ;<=625 clrf addhi clrf addmd movlw 5 subwf addlo ;roll over send: bsf porta,ldata call clock ;start bit (1) movf addlo,w call sndseg movf addmd,w call sndseg movf addhi,w call sndseg movlw 10 ;'l' call sndseg bcf porta,ldata movlw 10 movwf count flush: call clock ;colon call clock ;colon goto clock ;stop bit sndseg: call segtab ;get pattern movwf temp movlw 8 movwf count snd8: bcf porta,ldata btfsc temp,0 bsf porta,ldata call clock rrf temp decfsz count goto snd8 retlw 00 clock: bsf porta,lclock nop bcf porta,lclock retlw 00 segtab: addwf pcl retlw 0f6h ;0 led segment table retlw 014h ;1 for tsm6755 display retlw 0bah ;2 send bit0 first retlw 03eh ;3 retlw 05ch ;4 retlw 06eh ;5 retlw 0eeh ;6 retlw 034h ;7 retlw 0feh ;8 retlw 07eh ;9 retlw 0c2h ;l end