时间:2009-04-23 10:52
人气:
作者:admin

| DS89C450 Port Pin | J4 Header Pin | LCD Pin(s) | LCD Signal | Notes |
| P1.0 | 1 | 21 | 4A | Through 1kΩ |
| P1.1 | 2 | 20 | 4B | Through 1kΩ |
| P1.2 | 3 | 19 | 4C | Through 1kΩ |
| P1.3 | 4 | 18 | 4D | Through 1kΩ |
| P1.4 | 5 | 17 | 4E | Through 1kΩ |
| P1.5 | 6 | 22 | 4F | Through 1kΩ |
| P1.6 | 7 | 23 | 4G | Through 1kΩ |
| P1.7 | 8 | 1, 40 | COM | Connect directly |
| P2.0 | 21 | 25 | 3A | Through 1kΩ |
| P2.1 | 22 | 24 | 3B | Through 1kΩ |
| P2.2 | 23 | 15 | 3C | Through 1kΩ |
| P2.3 | 24 | 14 | 3D | Through 1kΩ |
| P2.4 | 25 | 13 | 3E | Through 1kΩ |
| P2.5 | 26 | 26 | 3F | Through 1kΩ |
| P2.6 | 27 | 27 | 3G | Through 1kΩ |
| P3.0 | 10 | 30 | 2A | Through 1kΩ |
| P3.1 | 11 | 29 | 2B | Through 1kΩ |
| P3.2 | 12 | 11 | 2C | Through 1kΩ |
| P3.3 | 13 | 10 | 2D | Through 1kΩ |
| P3.4 | 14 | 9 | 2E | Through 1kΩ |
| P3.5 | 15 | 31 | 2F | Through 1kΩ |
| P3.6 | 16 | 32 | 2G | Through 1kΩ |

Main: mov IE, #080h ; Disable timer 0 interrupt temporarily mov R2, DigitP1 ; Grab local copies of digit variables mov R3, DigitP2 mov R4, DigitP3 mov IE, #082h ; Re-enable timer 0 interrupt mov A, R2 call getDigit ; Calculate segment pattern for ones digit anl A, #01111111b ; Ensure that COM (P1.7) is driven low mov P1, A mov A, R3 call getDigit ; Calculate segment pattern for tens digit mov P2, A mov A, R4 call getDigit ; Calculate segment pattern for hundreds digit mov P3, A ;;;; Delay loop ;;;; mov R0, #0FFh L1A: mov R1, #0FFh L1B: djnz R1, L1B djnz R0, L1A ;;;;;;;;;;;;;;;;;;;;;; mov A, R2 call getDigit ; Calculate segment pattern for ones digit cpl A ; Inverse of the pattern driven on the first frame half orl A, #10000000b ; Ensure that COM (P1.7) is driven high mov P1, A mov A, R3 call getDigit ; Calculate segment pattern for tens digit cpl A ; Inverse of the pattern driven on the first frame half mov P2, A mov A, R4 call getDigit ; Calculate segment pattern for hundreds digit cpl A ; Inverse of the pattern driven on the first frame half mov P3, A ;;;; Delay loop ;;;; mov R0, #0FFh L2A: mov R1, #0FFh L2B: djnz R1, L2B djnz R0, L2A ;;;;;;;;;;;;;;;;;;;;;; ljmp Main ; Go back for another frame cycle (endless loop)注意,COM线(连接至P1.7)总是采用相同的波形驱动:前半帧为低电平,后半帧为高电平。对于段线,帧第一部分的模式驱动和第二部分的相反。以同样方式将三个数位的每一个分别连接至三个端口之一,所以,段A总是连接至Px.0,段B连接至Px.1,依此类推。这种配置使实例代码能够使用getDigit子程序来计算三个LCD显示板数位中每一个的段模式。
;*************************************************************************** ;* ;* getDigit ;* ;* Returns an LCD segment pattern (in Acc) for the decimal digit (0 to 9) ;* input (also in Acc) ;* getDigit: cjne A, #0, getDigit_not0 ; xgfedcba mov A, #00111111b ; Zero ret getDigit_not0: cjne A, #1, getDigit_not1 ; xgfedcba mov A, #00000110b ; One ret getDigit_not1: cjne A, #2, getDigit_not2 ; xgfedcba mov A, #01011011b ; Two ret getDigit_not2: cjne A, #3, getDigit_not3 ; xgfedcba mov A, #01001111b ; Three ret getDigit_not3: cjne A, #4, getDigit_not4 ; xgfedcba mov A, #01100110b ; Four ret getDigit_not4: cjne A, #5, getDigit_not5 ; xgfedcba mov A, #01101101b ; Five ret getDigit_not5: cjne A, #6, getDigit_not6 ; xgfedcba mov A, #01111101b ; Six ret getDigit_not6: cjne A, #7, getDigit_not7 ; xgfedcba mov A, #00000111b ; Seven ret getDigit_not7: cjne A, #8, getDigit_not8 ; xgfedcba mov A, #01111111b ; Eight ret getDigit_not8: cjne A, #9, getDigit_not9 ; xgfedcba mov A, #01101111b ; Nine ret getDigit_not9: mov A, #0 ret
mov TMOD, #021h ; Timer 1: 8-bit autoreload from TH1
; Timer 0: 16-bit
mov TCON, #050h ; Enable timers 0 and 1
mov CKMOD, #038h ; Use system clock for all timer inputs
mov IE, #082h ; Enable timer 0 interrupt
每次发生定时器中断时,寄存器中的延时计数器被递减。当延时计数器达到零时,LCD 3位计数器值递增1 (根据需要,每一数位翻转);延时计数器初始化到其最大值。由于定时器0宽度是16位,实例代码将延时计数器设置为20,3位计数器大概每(1/16.384MHz) × (216) × 20 = 0.08s ,即每秒12次,递增一次。 org 000Bh ; Timer 0 interrupt
ljmp IntTimer0
;***************************************************************************
;*
;* IntTimer0 (INTT0)
;*
;* Timer interrupt service routine
;*
IntTimer0:
push ACC ; Save off accumulator and R0
push R00
mov R0, Count ; Only increment LCD digits every [CountMax]
; interrupt cycles
djnz R0, INTT0_Done
inc DigitP1 ; Increment ones digit on display
mov A, DigitP1
cjne A, #10, INTT0_Continue ; Check for rollover
mov DigitP1, #0
inc DigitP2 ; Increment tens digit on display
mov A, DigitP2
cjne A, #10, INTT0_Continue ; Check for rollover
mov DigitP2, #0
inc DigitP3 ; Increment hundreds digit on display
mov A, DigitP3
cjne A, #10, INTT0_Continue ; Check for rollover
mov DigitP3, #0
INTT0_Continue:
mov R0, CountMax ; Reset to starting cycle count
INTT0_Done:
mov Count, R0 ; Update cycle counter
pop R00
pop ACC ; Restore accumulator and R0
reti