| MAX7219测试程序
说明:MAX7219是美国MAXIM公司推出的三线串行8位LED显示驱动器,具有多种显示(可控)方式。
;Program Test MAX7219 ;This program is used to test whether MAX7219 is Ok and give a demo about ho w to use it. ;Program Writed by Ouyijie, 1998.10 ;Jialijie Computer Studio PCL EQU 2 ;PCL = 2 DCOMMAND EQU 0x0d DDATA EQU 0x0e MCU_Reset ;I/O RB1 is Clock line ;I/O RB2 is LOAD line ;I/O RB3 is DATA line ;I/O RB4 is LED ,show state movlw b‘00000000‘ ;set first I/O direction tris 6 movlw b‘00000000‘ ;set first I/O state movwf 0x06 Start call MAX7219_Reset comf 0x06,f call Delay1s goto Start MAX7219_Reset ;reset MAX7219 ;0x0d is display command ;0x0e is display data movlw 0x0c movwf DCOMMAND movlw 0x00 movwf DDATA call Write7219 ;write in 0c00H, shut down MAX7219. call Delay1ms ;wait leaest 250us. movlw 0x09 movwf DCOMMAND movlw 0x3f movwf DDATA call Wr ite7219 ;write in 091fH, digits 0 to 5 are transcode. call Delay1ms movlw 0x0a movwf DCOMMAND movlw 0x0a movwf DDATA call Write7219 ;write in 0a0fH, set MAX7219 is the brightest state. call Delay1ms movlw 0x0b movwf DCOMMAND movlw 0x05 movwf DDATA call Write7219 ;set SCAN LIMIT is digits 0 to 5. call Delay1ms ;movlw 0x0f ;movwf DCOMMAND ;movlw 0x00 ;movwf DDATA ;call Write7219 ;wirte in 0f00H, exit TEST, go into normal state. ;call Delay1ms ;Begin set Digit Datas movlw 0x01 movwf DCOMMAND movlw 0x00 movwf DDATA call Write7219 ;bit0 is 0 call Delay1ms movlw 0x02 movwf DCOMMAND movlw 0x01 movwf DDATA call Write7219 ;bit1 is 1 call Delay1ms movlw 0x03 movwf DCOMMAND movlw 0x02 ;bit2 is 2 movwf DDATA call Write7219 call Delay1ms movlw 0x04 movwf DCOMMAND movlw 0x03 ;bit3 is 3 movwf DDATA call Write7219 call Delay1ms movlw 0x05 movwf DCOMMAND movlw 0x04 ;bit4 is 4 movwf DDATA call Write7219 call Delay1ms movlw 0x06 movwf DCOMMAND movlw 0x05 movwf DDATA call Write7219 ;bit5 is 5 call Delay1ms ;Begin Display movlw 0x0c movwf DCOMMAND movlw 0x01 movwf DDATA call Write7219 ;write in 0c01H, exit shut down state. call Delay1s ;wait for 3 seconds. ;call Delay1s ;call Delay1s ;movlw 0x0c ;movwf DCOMMAND ;movlw 0x00 ;movwf DDATA ;call Write7219 ;write in 0c00H, shut down MAX7219. call Delay1s return AddressTable ;list of display data addwf PCL retlw 0x0 ;NO-OP retlw 0x1 ;DIG 0 retlw 0x2 ;DIG 1 retlw 0x3 ;DIG 2 retlw 0x4 ;DIG 3 retlw 0x5 ;DIG 4 retlw 0x6 ;DIG 5 retlw 0x7 ;DIG 6 retlw 0x8 ;DIG 7 retlw 0x9 ;DECODE MODE retlw 0xa ;INTENSITY retlw 0xb ;SCAN LIMIT retlw 0xC ;SHUIDOWN Write7219 ;this function use address 0x0c,0x0d,0x0e,0x0f. ;address 0x0c is data send to MAX7219 ;address 0x0d is display command ;address 0x0e is display data ;address 0x0f is cont used ;write address 0x0c to MAX7219 each time bcf 0x06,2 ;set LOAD is low and MAX7219 begin to recive data movlw 0x08 movwf 0x0f movf DCOMMAND,w ;send display address to MAX7219 movwf 0x0c call SendData movlw 0x08 movwf 0x0f movf DDATA,w ;send display data to MAX7219 movwf 0x0c call SendData ;set a puls from LOAD to MAX7219 bcf 0x06,2 ;LOAD = 0 bsf 0x06,2 ;LOAD = 1 nop ;wait 3 comand times. nop nop bcf 0x06,2 ;LOAD = 0 nop return SendData ;this function is used to send data in address 0x0c to MAX7219 from the high est place. bcf 0x06,3 ;CLOCK = 0 bcf 0x06,1 ;DATA = 0 btfsc 0x0c,7 ;if bit7 of 0x0c is 0 then skip next command. bsf 0x06,1 ;DATA = 1 nop nop nop ;wait 3 command times. nop nop bsf 0x06,3 ;CLOCK = 1 nop nop nop ;delay 5 comand times and clean the Watchdog. clrwdt nop nop nop nop nop bcf 0x06,3 ;CLOCK = 0 rlf 0x0c,1 ;0x0c move left a bit. decfsz 0x0f,1 ;0x0f = 0x0f - 1, if x00f = 0 then return to Write7219. goto SendData return Delay1ms movlw 0x28 ;0x25 = 40D = 28H movwf 0x0c delay1ms_loop1 movlw 0x05 movwf 0x0f delay1ms_loop2 ;40 * 25 = 1000 us = 1ms clrwdt ;clean watchdog decfsz 0x0f,1 goto delay1ms_loop2 decfsz 0x0c,1 goto delay1ms_loop1 return Delay1s movlw 0xce ;every time use 4.85ms, 1000/4.85=206.1D=CEH movwf 0x1a delay1s_loop1 movlw 0x05 movwf 0x1b delay1s_loop2 ;4.85 ms * 206 = 1 s clrwdt call Delay1ms decfsz 0x1b,1 goto delay1s_loop2 decfsz 0x1a,1 goto delay1s_loop1 return end (综合电子论坛) |
*注:部份文章为网上收录供大家共同学习参考之用,并不代表本站意见。如存在版权问题请马上通知我们,我们将马上删除。 |