 |
| 昵称:md9 |
| 级别:副军长 |
| 经验值:3130 |
| 贡献值:9791 |
给他留言 |
| 来自:深圳 |
|
这是我的程序:(因为刚刚开始用AVR,从最简单的开始,就直接用汇编了) Timer2用外接32768晶振提供时钟,整个系统耗电大约30微安。
; lcddisplay.asm
; Test raw LCD display
.include "m48def.inc" .org 0x0000 rjmp start
.org OC2Aaddr rjmp isr_timer2
.org 0x0020 table: .DB 0b11101101, 0b00101000, 0b10110101, 0b10111001 .DB 0b01111000, 0b11011001, 0b11011101, 0b10101000 .DB 0b11111101, 0b11111001 start: ldi r16, 1<<PUD out MCUCR, r16 ; disable all I/O pull-up
ldi r16, 1<<AS2 sts ASSR, r16 ; enable asynchronous mode ldi r16, 1<<WGM21 sts TCCR2A, r16 ; CTC mode ldi r16, 31 sts OCR2A, r16 ; preset compare A
ldi r16,1<<CS21 ; divide by 8 ; ldi r16,1<<CS20 ; use clkIO as source sts TCCR2B, r16 ldi r16, 1<<OCF2A out TIFR2, r16 ; clear flag
ldi r16, 1<<OCIE2A sts TIMSK2, r16 ; enable interrupt on compare match A ser r16 out DDRD, r16 ; Port D output -- LCD segment control clr r5 ldi r16, 0x55 mov r6, r16 clr r7 clr r8 ldi r16, 9 mov r10, r16 mov r11, r16 mov r12, r16 mov r13, r16 dec r10 sei ; enable global interrupt
ldi r16, (1<<SE) out SMCR, r16 ; use Idle mode here, waiting 1 second clr r2 iniw:sleep dec r2 brne iniw
ldi r16, (1<<SM1)|(1<<SM0)|(1<<SE) out SMCR, r16 ; use power-save mode nop nop clr r2 loop: nop nop sleep nop nop dec r2 dec r2 breq adjtime rjmp loop adjtime: ldi r17, 10 inc r10 cp r10, r17 brne updcount clr r10 inc r11 cp r11, r17 brne updcount clr r11 inc r12 cp r12, r17 brne updcount clr r12 inc r13 cp r13, r17 brne updcount clr r13 updcount: rcall calcor rjmp loop isr_timer2: clr r16 out DDRC, r16 ; float all COMx pins
bst r4, 1 brts show34 bst r4, 0 brts show2 mov r0, r5 ldi r18, 1 rjmp sel show2: mov r0, r6 ldi r18, 1<<1 rjmp sel show34: bst r4, 0 brts show4 mov r0, r7 ldi r18, 1<<2 rjmp sel show4: mov r0, r8 ldi r18, 1<<3 sel: bst r4, 2 brtc lcden com r0 com r16 lcden: out PORTC, r16 out PORTD, r0 out DDRC, r18 iext:inc r4 reti
calcor: ; translate R10~~R13 to R5~~R8 clr r5 clr r6 clr r7 clr r8 ldi ZH, high(table<<1) ldi ZL, low(table<<1) add ZL, r10 lpm ; load table data to R0 rcall filler ldi ZL, low(table<<1) add ZL, r11 lpm rcall filler ldi ZL, low(table<<1) add ZL, r12 lpm rcall filler ldi ZL, low(table<<1) add ZL, r13 lpm rcall filler ret
filler: rol r0 rol r5 rol r0 rol r5 rol r0 rol r6 rol r0 rol r6 rol r0 rol r7 rol r0 rol r7 rol r0 rol r8 rol r0 rol r8 ret
|