⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 set_time.asm

📁 avr读写DS1302的程序和LCD的驱动!
💻 ASM
📖 第 1 页 / 共 4 页
字号:
.include  "m48def.inc" 
.def      clrtemp    =r2
.def      spitab     =r3
.def      lcdtab     =r4        
.def      rxtab      =r5
.def      keytab0    =r6
.def      keytab1    =r7
.def      keytab2    =r8
.def      keytab3    =r9
.def      keytab4    =r10
.def      addsum     =r11
.def      maintab    =r12
.def      regtemp    =r13
.def      lcdinc     =r14

.def      tempa      =r15
.def      tempb      =r16
.def      tempc      =r17
.def      tempd      =r18
.def      tempe      =r19
.def      tempf      =r20
.def      buffbit    =r21
.def      keybit     =r22
.def      rxtemp     =r23

.def      regr24     =r24
.def      regr25     =r25 

.equ      rst        =$02       ; 复位总线
.equ      sdo        =$03
.equ      sdi        =$04
.equ      sck        =$05

.equ      lcd_e      =$05
.equ      lcd_rs     =$04


.equ      sram0      =$100

.equ      dsbuffsram =$100
.equ      keydel0    =$101
.equ      keydel1    =$102
.equ      lcdincsram0 =$103
.equ      lcdincsram1 =$104     
.equ      incsram     =$105
.equ      rxincsram   =$106


.equ      timesram   =$110
.equ      min1sraml  =$111
.equ      hr1sraml   =$112
.equ      min1sramh  =$113
.equ      hr1sramh   =$114

.equ      min2sraml  =$115
.equ      hr2sraml   =$116
.equ      min2sramh  =$117
.equ      hr2sramh   =$118

.equ      min3sraml  =$119
.equ      hr3sraml   =$11a
.equ      min3sramh  =$11b
.equ      hr3sramh   =$11c

.equ      srcsram    =$11d      ; 接收数据缓冲
.equ      minsram    =$11e
.equ      hrsram     =$11f
.equ      datesram   =$120

.equ      monthsram  =$121
.equ      daysram    =$122
.equ      yearsram   =$123
.equ      yearsramh  =$124
.equ      wpsram     =$125



.equ      command    =$126
.equ      Tdelay     =$127
.equ      lcdsram    =$128
.equ      lcddel     =$129
.equ      lcdsramtemp =$12a
.equ      ComData    =$12b 


.equ      lcdsram1   =$130
.equ      lcdsram2   =$140
.equ      lcdtemp    =$150


.equ      timesramt  =$180
.equ      min1sramlt =$181
.equ      hr1sramlt  =$182
.equ      min1sramht =$183
.equ      hr1sramht  =$184

.equ      min2sramlt =$185
.equ      hr2sramlt  =$186
.equ      min2sramht =$187
.equ      hr2sramht  =$188

.equ      min3sramlt =$189
.equ      hr3sramlt  =$18a
.equ      min3sramht =$18b
.equ      hr3sramht  =$18c

.equ      srctemp    =$18d      ; 接收数据缓冲
.equ      mintemp    =$18e
.equ      hrtemp     =$18f
.equ      datetemp   =$190
.equ      monthtemp  =$191
.equ      daytemp    =$192
.equ      yeartemp   =$193
.equ      yeartemph  =$194

;======================================
.equ      kmodebit   =$00
.equ      ksetbit    =$01
.equ      kaddbit    =$02
.equ      keydnbit   =$03

.equ      kmode_bit  =$01
.equ      kset_bit   =$02
.equ      kadd_bit   =$04
.equ      keydn_bit  =$08


;.equ      disp0      =$00
;.equ      disp1      =$01
;.equ      disp2      =$02
;.equ      disp3      =$03
;.equ      disp4      =$04
;.equ      disp5      =$05
;.equ      disp6      =$00

;bit
.equ      bit0       =$00
.equ      bit1       =$01
.equ      bit2       =$02
.equ      bit3       =$03
.equ      bit4       =$04
.equ      bit5       =$05
.equ      bit6       =$06
.equ      bit7       =$07

.equ      bit_0      =$01
.equ      bit_1      =$02
.equ      bit_2      =$04
.equ      bit_3      =$08
.equ      bit_4      =$10
.equ      bit_5      =$20
.equ      bit_6      =$40
.equ      bit_7      =$80

          .org      $0000
		  rjmp      reset       ;0
		  reti                  ;1
		  reti                  ;2
		  reti                  ;3
          reti                  ;4
          reti                  ;5
          reti		            ;6
		  reti                  ;7
		  reti    	            ;8
		  reti                  ;9
		  reti		            ;a
		  reti                  ;b
		  reti		            ;c 
		  reti                  ;d
          reti		            ;e
		  reti                  ;f
          reti                  ;10
		  reti                  ;11
		  rjmp       rxint      ;12
		  reti		            ;13 
		  reti                  ;14
		  reti                  ;15
		  reti                  ;16
		  reti                  ;17
		  reti                  ;18
		  reti                  ;19
;**************************************************
reset:
          wdr 
		  cli 
          ldi      tempc,high(ramend)
		  out      sph,tempc
		  ldi      tempc,low(ramend)
		  out      spl,tempc
		  ldi      tempc,0b00011100
		  sts      wdtcsr,tempc
;**************************************************
          clr      tempc
 		  ldi      zh,high(sram0)
		  ldi      zl,low(sram0)
		  ldi      yl,$00
		  ldi      yh,$02

clrsram:
          st       Z+,tempc
          sbiw     yl,$01
		  brne     clrsram

		  ldi      tempc,0b11111000
		  out      portb,tempc

		  ldi      tempc,0b10101111
		  out      ddrb,tempc

          ldi      tempc,0b11111111
		  out      portd,tempc

          ldi      tempc,0b00001110
          out      ddrd,tempc

          ldi      tempc,0b00000000
		  out      portc,tempc

          ldi      tempc,0b00111111
		  out      ddrc,tempc
		  sbi      portb,pb1
		  cbi      portb,rst
		  cbi      portb,sck
		  sbi      portd,pd2

          rcall    lcdinit
          rcall    Write_Enable  
          rcall    write_tcs
		  ldi      zh,$00
		  ldi      zl,$10
		  ldi      yh,high(timesram)
		  ldi      yl,low(timesram)
		  ldi      tempe,12
		  rcall    EEPROM_RD
		  cpi      tempd,$08
		  brlo     rd0
		  clr      tempd
rd0:
		  st       y+,tempd
rd1:
		  adiw     zl,$01
		  rcall    EEPROM_RD
		  cpi      tempd,$5a
		  brlo     rd2
		  clr      tempd
rd2:
		  st       y+,tempd
		  dec      tempe
		  brne     rd1         
                    
          ldi      zh,high(lcdtab000*2)
		  ldi      zl,low(lcdtab000*2)
          ldi      yh,high(lcdsram1)
		  ldi      yl,low(lcdsram1)
		  ldi      tempd,32
lcd_mov:
		  lpm      tempc,z+
		  st       y+,tempc
		  dec      tempd
		  brne     lcd_mov 
		  clr      clrtemp
		  clr      buffbit
		  clr      lcdtab 
		  clr      spitab 
		  clr      keytab0
		  clr      keytab1
		  clr      keytab2
		  clr      keytab3
		  clr      keytab4
		  clr      keybit
		  clr      rxtab
		  ldi      tempc,$20
	      sts      yearsramh,tempc
		  ldi      tempc,$01
		  sts      ubrr0l,tempc    ;250k
		  clr      tempc
		  sts      ubrr0h,tempc      
;		  ldi      tempc,0b00100000    ;BGB
;		  sts      ucsr0a,tempc
          ldi      tempc,0b10011100
          sts      ucsr0b,tempc
;		  ldi      tempc,0b00001100
;		  sts      ucsr0c,tempc
;**************************************************
main:   
          wdr
     	  rcall    lcddisp
          rcall    key
		  rcall    keypr
          sbrs     buffbit,bit5
		  rjmp     main01
		  cbr      buffbit,bit_5
		  mov      tempc,keytab2
		  cpi      tempc,$00
		  brne     main00
          rcall    writeds1302
		  rjmp     main01 
main00: 
		  ldi      zh,$00
		  ldi      zl,$10
		  ldi      tempe,13
		  ldi      yh,high(timesram) 
          ldi      yl,low(timesram)
wrt0:
		  ld       tempc,y+ 
		  rcall    EEPROM_WR
		  adiw     zl,$01
		  dec      tempe
		  brne     wrt0
main01:
          sbrs     buffbit,bit0
		  rjmp     main
		  ldi      zh,high(main_tab)
		  ldi      zl,low(main_tab)
		  add      zl,maintab
		  adc      zh,clrtemp
		  ijmp    
main_tab:
          rjmp     main0
          rjmp     main1
		  rjmp     main2
		  rjmp     main3
		  rjmp     main4
main0: 
		  rcall    readds1302	 
          lds      tempc,lcdsramtemp         
		  lds      tempd,srcsram
		  cp       tempc,tempd
		  breq     main  
		  sts      lcdsramtemp,tempd   
		  rcall    srammovlcd_d
		  rcall    srammovlcd_t
		  rjmp     main  
;**************************************************
;bit1
main1:
main2:
          lds      zh,lcdincsram1
		  lds      zl,lcdincsram0
		  sbiw     zl,$01
		  sts      lcdincsram0,zl
		  sts      lcdincsram1,zh
		  brne     main1_1
		  ldi      tempc,$60
		  sts      lcdincsram1,tempc
		  mov      tempc,maintab
		  cpi      tempc,$01
		  brne     main1_0
		  rcall    movlcd
		  rjmp     main
main1_0:
          rcall    movlcd0
main1_1:
		  rjmp     main
;**************************************************
main3:
main4:
          sbrs     buffbit,bit3
		  rjmp     main
          sbrs     buffbit,bit2
		  rjmp     main3_0
		  cbr      buffbit,bit_2
		  cli
		  clr      tempc
		  clr      rxtab
		  sts      incsram,tempc
		  sts      lcdincsram0,tempc
          ldi      tempc,$20
          sts      lcdincsram1,tempc
		  ldi      tempd,$06
		  ldi      zh,high(lcdsram2+8)
		  ldi      zl,low(lcdsram2+8)
          mov      tempc,maintab
		  cpi      tempc,$03
		  brne     main3_000
          rcall    sendread
		  rjmp     main3_00
main3_000:
		  adiw     zl,$01
		  rcall    sendwrite
main3_00:
          sei
		  ldi      tempc,$20		   
          cbi      portd,pd2
          st       z+,tempc
		  dec      tempd
		  brne     main3_00
main3_0:
          cbi      portd,pd2		   		 
          lds      zh,lcdincsram1
		  lds      zl,lcdincsram0
		  sbiw     zl,$01
		  sts      lcdincsram0,zl
		  sts      lcdincsram1,zh
		  brne     main3_5
		  ldi      tempc,$60
		  sts      lcdincsram1,tempc
main3_1:		    
		  clr      tempc
		  ldi      tempd,$2e
		  ldi      zh,high(lcdsram2+8)
		  ldi      zl,low(lcdsram2+8)
		  mov      tempe,maintab
		  cpi      tempe,$03
		  breq     main3_2
		  adiw     zl,$01
main3_2:
          st       z+,tempd
		  inc      tempc
		  lds      tempe,incsram		  
		  cp       tempc,tempe
		  brlo     main3_2
		  inc      tempe
		  sts      incsram,tempe    
		  cpi      tempe,$07
		  brlo     main3_5
		  sbi      portd,pd2          
		  cbr      buffbit,bit_3
          mov      tempc,maintab
		  cpi      tempc,$04
          brne     main3_3
		  cbr      keybit,0b00110111
		  sbr      keybit,keydn_bit
		  dec      keytab0
		  rjmp     main
main3_3:
          sbrc     buffbit,bit4
          rjmp     main3_4  
main3_30:		   
		  rcall    kdisp1004    
          rjmp     main
main3_4:
          ldi      yh,high(timesram)
		  ldi      yl,low(timesram)
		  ldi      zh,high(timesramt)
		  ldi      zl,low(timesramt)
          ldi      tempe,13
comp:
          ld       tempc,y+
		  ld       tempd,z+
		  cp       tempc,tempd
		  brne     main3_30     
		  dec      tempe
		  brne     comp
          rcall    kdisp1005
          rcall    rdtimemovlcd_d
		  rcall    rdtimemovlcd_t
main3_5:
          rjmp     main
;**************************************************
lcddisp:
          cbi      portc,lcd_e
          lds      tempc,lcddel
		  dec      tempc
		  sts      lcddel,tempc
		  brne     DISP0_1     
          ldi      tempc,10
		  sts      lcddel,tempc
    	  ldi      zh,high(lcd_tab)
		  ldi      zl,low(lcd_tab)
          add      zl,lcdtab
		  adc      zh,clrtemp
		  ijmp       
lcd_tab:
          rjmp     disp0
		  rjmp     disp1
		  rjmp     disp2
		  rjmp     disp3
          
		  rjmp     disp4
		  rjmp     disp5
		  rjmp     disp6
		  rjmp     disp7
;=============================================== 
disp0:       
  		  ldi      tempc,$08
		  rjmp     disp0_0
disp4:
		  ldi      tempc,$0c
disp0_0:
          out      portc,tempc
		  inc      lcdtab
		  clr      lcdinc
          sbi      portc,lcd_e
DISP0_1:
		  ret
;=============================================== 
disp1:
disp5:
          clr      tempc
	      out      portc,tempc
		  inc      lcdtab
		  clr      lcdinc
          sbi      portc,lcd_e
		  ret
;=============================================== 
disp2:
	      ldi      zh,high(lcdsram1)
		  ldi      zl,low(lcdsram1)
		  rjmp     disp2_0
disp6:
		  ldi      zh,high(lcdsram2)
		  ldi      zl,low(lcdsram2) 
disp2_0:
	      add      zl,lcdinc
	      adc      zh,clrtemp
		  ld       tempc,z
		  sts      lcdsram,tempc
		  swap     tempc
		  andi     tempc,$0f
		  sbr      tempc,bit_4
		  out      portc,tempc
		  inc      lcdtab
		  sbi      portc,lcd_e
		  ret
;=============================================== 
disp3:
disp7:
          dec      lcdtab
          lds      tempc,lcdsram
          andi     tempc,$0f
		  sbr      tempc,bit_4
		  out      portc,tempc
		  inc      lcdinc
		  mov      tempc,lcdinc
          cpi      tempc,16
		  brlo     disp3_0
		  ldi      tempc,$04

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -