home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Acorn User 9
/
AU_CD9.iso
/
Cover_Discs
/
Back_Issues
/
1998_13
/
Regulars
/
RTR
/
LEDtst
next >
Wrap
Text File
|
1998-10-09
|
8KB
|
264 lines
;Multiplexed LED matrix display test
;For an 10 MHz clock
;A0 - Serial out
;A1 - Serial in
;A2 - CTS allows serial input
;A3 - RTS output held until this is low
;Note for 16F84 invert the state of the PWRTE
LIST P=16C84
C EQU 0
PCL EQU 2
Z EQU 2
PORTB EQU 6
PORTA EQU 5
TRISB EQU 86H
TRISA EQU 85H
EECON1 EQU 88H
EEDATA EQU 8
INTCON EQU 0bH
EEADR EQU 9
STATUS EQU 3
RP0 EQU 5
INC EQU 1
cts EQU 2
rts EQU 3
; Output bits
cdat EQU 1 ;Coloum data
cck EQU 2 ;Coloum clock
rclr EQU 3 ;Row clear
rck EQU 4 ;Row clock
rdat EQU 5 ;Row data
sBuf EQU 0ch ;Serial send buffer
Scount EQU 0dh ;Tempory Counter
Cdown EQU 0eh ;Time delay countdown
rBuf EQU 0fh ;Recieve buffer
ScanNo EQU 10h ;Number of row we are on
RowC EQU 11h ;Row counter
Sstore EQU 12h ;Scrole store
Com1 EQU 13h ;Command 1
Com2 EQU 14h ;Command 2
save_w EQU 15h ;save w reg
save_s EQU 16H ;save status
save_p EQU 17h ;save port LEDs
DisBuf EQU 1Ah ;Display buffer
;
ORG 0
GOTO Start
ORG 4
movwf save_w ;save w and s regs
swapf STATUS,w ;swapf doesn't affect Z like movf
movwf save_s
movf PORTB,w ;Save state of LEDs
movwf save_p
clrf PORTB ;Turn LEDs off
call Rx ;Recieve byte
incf Com2,f ;Increment the data to put in
call sleft ;Scroll left command
out movf save_p,w
movwf PORTB ;Turn LEDs back on
swapf save_s,w
movwf STATUS ; restore registers
swapf save_w,f
swapf save_w,w
bcf INTCON,1 ;Clear edge interrupt
retfie
;Recieve a serial byte
Rx movlw 8 ;Number of data bits to get
movwf Scount
Sb btfsc PORTA,1 ;Hold until start bit
goto Sb
call hDelay ;Half a baud delay
Rnb bcf STATUS,C ;Clear the carry bit
rrf rBuf,f ;Prepare for next bit
call rDelay ;Full baud delay for recieve
btfsc PORTA,1 ;Test input
bsf rBuf,7 ;Set if needed
decfsz Scount,f ;See if finished
goto Rnb ;Round again if not
call rDelay ;Allow for stop bit to start
movf rBuf,w ;Put recieved chractor into W
return
;Send a serial byte
Send btfsc PORTA,rts ;Only proceed when rts is low
goto Send
movlw 9 ;Number of data bits to send
movwf Scount
bcf PORTA,0 ;Start bit
call cDelay ;Extra delay compensation
Sloop call Delay
btfsc sBuf,0 ;Set the next bit
bsf PORTA,0
btfss sBuf,0
bcf PORTA,0
rrf sBuf,f ;Shift for next time
decfsz Scount,f
goto Sloop ;Round until finished
bsf PORTA,0 ;Stop bit
call cDelay ;Extra delay compensation
call Delay
call Delay
call cDelay ;For good measure
return
cDelay movlw 2 ;Small delay at end of send
movwf Cdown
goto Dloop
hDelay movlw 21 ;half delay for serial recieve 10MHz clock
movwf Cdown ; 19,200 Baud rate
goto Dloop
rDelay movlw 38 ;Delay for serial recieve 10MHz clock
movwf Cdown ; 19,200 Baud rate
goto Dloop
Delay movlw 39 ;Delay for serial send 10MHz clock
movwf Cdown ; 19,200 Baud rate
Dloop decfsz Cdown,f
goto Dloop
return
Start
BSF STATUS,RP0 ;SELECT REGISTER BANK 1
MOVLW 1Ah ;Bits 4,3 & 2 inputs
MOVWF TRISA^80H
MOVLW 1 ;Bit 0 input rest outputs
MOVWF TRISB^80H
MOVLW 3 ;16 prescaler -ve edge interrupt
MOVWF 1 ;Option register
MOVLW 90H ;Enable bit 0 interrupt
MOVWF INTCON
BCF STATUS,RP0 ;SELECT REGISTER BANK 0
BSF PORTA,0 ;Serial at Mark
BCF PORTA,cts ;CTS enabled
CLRF PORTB
CLRF ScanNo
CLRF Com2
;Just put some test data into some memory
movlw 0AAh
movwf DisBuf
movwf DisBuf!1
movwf DisBuf!2
movwf DisBuf!6
movwf DisBuf!7
movwf DisBuf!8
movwf DisBuf!12
movwf DisBuf!13
movwf DisBuf!14
movwf DisBuf!18
movwf DisBuf!19
movwf DisBuf!20
movlw 055h
movwf DisBuf!3
movwf DisBuf!4
movwf DisBuf!5
movwf DisBuf!9
movwf DisBuf!10
movwf DisBuf!11
movwf DisBuf!15
movwf DisBuf!16
movwf DisBuf!17
Main btfss 0bh,2 ;Test timer
GOTO Main ;Loop until time
bcf 0bh,2 ;Clear it for next time
incf ScanNo,f
movlw 7 ;See if it is at end
subwf ScanNo,w
btfsc STATUS,Z ;Wrap it round after 7
clrf ScanNo
call scan
GOTO Main
scan clrf PORTB ; Blank out row
bcf STATUS,C
rlf ScanNo,w ;Scan No * 3 + DisBuf = reg address
addwf ScanNo,w
addlw DisBuf
movwf 4 ;to indirect register
call rbout ;Output first byte
incf 4,f ;Next byte
call rbout
incf 4,f ;Last byte
call hrout
movf ScanNo,w
movwf RowC ;Row Count
incf RowC,f ;One more pulse
bcf STATUS,C
rlf RowC,f
rlf RowC,f
rlf RowC,w
movwf PORTB
return
hrout movlw 4 ;Only 4 bits out
GOTO he
rbout movlw 8 ;number of shifts to do
he movwf RowC ;shift store
movf 0,w ;get byte to send
movwf Sstore ;store it
rloop rrf Sstore,f ;get next bit into carry
bcf PORTB,cdat ;Get data line right
btfsc STATUS,C
bsf PORTB,cdat
bsf PORTB,cck ;Toggle clock
bcf PORTB,cck
decfsz RowC,f ;All bits done?
GOTO rloop
return
;Commands
sleft movlw DisBuf ;Scroll memory left
movwf 4 ;into indirect register
movlw 7 ;Number of rows to scroll
movwf sBuf ;Temp storage
bcf STATUS,C
slloop rlf 0,f ;Move first byte
incf 4,f
rlf 0,f ;Move second byte
incf 4,f
rlf 0,f ;Move last byte
bcf 0,4 ;Blank bit fallen off the end
incf 4,f ;Move on for next time
decfsz sBuf,f ;Loop until all 7 rows are out
goto slloop
btfsc Com2,0 ;Now put new data in
bsf DisBuf,0
btfsc Com2,1
bsf DisBuf!3,0
btfsc Com2,2
bsf DisBuf!6,0
btfsc Com2,3
bsf DisBuf!9,0
btfsc Com2,4
bsf DisBuf!12,0
btfsc Com2,5
bsf DisBuf!15,0
btfsc Com2,6
bsf DisBuf!18,0
return
end