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

📄 set_time.asm

📁 avr读写DS1302的程序和LCD的驱动!
💻 ASM
📖 第 1 页 / 共 4 页
字号:
		  ret
;**************************************************
keyp3010:
		  sbrs    keybit,bit5
          rcall   kdisp301
          sbrs    keybit,kmodebit          
          rjmp    keyp301_0
		  cbr     keybit,kmode_bit
          rcall   lcdincmov
		  inc     keytab4
		  mov     tempc,keytab4
		  cpi     tempc,$06
		  brlo    keyp301_0
		  clr     keytab4
keyp301_0:                           
          sbrs    keybit,kaddbit
		  rjmp    keyp301_1
		  cbr     keybit,kadd_bit
		  sbr     keybit,bit_6  
          rcall   lcdincmov0
          ldi     zh,high(time_tab1)
		  ldi     zl,low(time_tab1)
		  add     zl,keytab4
		  adc     zh,clrtemp
		  ijmp    
time_tab1:
		  rjmp    timeyy2
		  rjmp    timeyy3
		  rjmp    timemm0
		  rjmp    timemm1
		  rjmp    timedd0
		  rjmp    timedd1
timeyy2:
          lds     tempc,yearsram
		  mov     tempd,tempc
		  andi    tempd,$0f
		  andi    tempc,$f0
		  ldi     tempb,$10
		  add     tempc,tempb
		  cpi     tempc,$a0
		  brlo    timeyy2_0 
		  clr     tempc
timeyy2_0:
          or      tempc,tempd
		  sts     yearsram,tempc		    
keyp301_1:
          rcall   srammovlcd_d0 
		  rcall   lcdmovtemp 
		  ret		  	  	
timeyy3:
          lds     tempc,yearsram
		  mov     tempd,tempc
		  andi    tempd,$f0
		  andi    tempc,$0f
		  inc     tempc
		  cpi     tempc,$0a
		  brlo    timeyy2_0    
		  clr     tempc
          rjmp    timeyy2_0
timemm0:
          lds     tempc,monthsram
		  mov     tempd,tempc
		  andi    tempd,$0f
		  andi    tempc,$f0
		  ldi     tempb,$10
          add     tempc,tempb
		  cpi     tempc,$20
          brlo    timemm0_1   
		  clr     tempc
		  cpi     tempd,$00
		  brne    timemm0_0
		  ldi     tempd,$01
timemm0_0:
		  or      tempc,tempd
		  sts     monthsram,tempc
          rjmp    keyp301_1
timemm0_1:
          cpi     tempd,$03
		  brlo    timemm0_0
		  clr     tempd
		  cpi     tempc,$00
		  brne    timemm0_0
		  ldi     tempd,$01
          rjmp    timemm0_0
timemm1:
          lds     tempc,monthsram
		  mov     tempd,tempc
		  andi    tempd,$0f
		  andi    tempc,$f0
		  inc     tempd
		  cpi     tempc,$10
          brlo    timemm1_1   
		  cpi     tempd,$03
		  brlo    timemm0_0
		  clr     tempd
timemm1_1:
		  cpi     tempd,$0a
		  brlo    timemm1_2
		  clr     tempd
timemm1_2:
          cpi     tempc,$00
		  brne    timemm1_3    
		  cpi     tempd,$00
		  brne    timemm1_3
		  ldi     tempd,$01
timemm1_3:
		  or      tempc,tempd
		  sts     monthsram,tempc
          rjmp    keyp301_1
timedd0:
timedd1:
          lds     tempf,monthsram
		  cpi     tempf,$02
		  brne    timedd0_0 
     	  lds     tempc,yearsram
		  mov     tempd,tempc
		  andi    tempc,$0f
		  andi    tempd,$f0
		  ldi     tempe,10
		  mul     tempd,tempe
		  ldi     tempe,$07
		  ldi     tempd,$d0
		  add     tempd,r0
		  adc     tempe,r1
		  add     tempd,tempc
		  adc     tempe,clrtemp
          clr     tempc
		  lsr     tempe
		  ror     tempd
		  ror     tempc
		  lsr     tempe
		  ror     tempd
		  ror     tempc
		  ldi     tempe,$29
		  tst     tempc
		  brne    timedd0_1    
		  ldi     tempe,$30
timedd0_0:
          ldi     tempe,$31
		  cpi     tempf,$04
		  breq    timedd0_1
		  cpi     tempf,$06
		  breq    timedd0_1
		  cpi     tempf,$09
		  breq    timedd0_1
		  cpi     tempf,$11
		  breq    timedd0_1
		  ldi     tempe,$32		   
timedd0_1:                   
          lds     tempc,datesram 
		  mov     tempd,tempc
		  andi    tempd,$0f
		  andi    tempc,$f0
		  mov     tempf,keytab4
		  cpi     tempf,$04
		  brne    timedd0_3 
		  ldi     tempb,$10  		       
          add     tempc,tempb
		  mov     tempa,tempc
		  or      tempa,tempd
          cp      tempa,tempe
		  brlo    timedd0_2
		  clr     tempc
          cpi     tempd,$00
		  brne    timedd0_2
		  ldi     tempd,$01
timedd0_2:
		  or      tempc,tempd
		  sts     datesram,tempc
          rjmp    keyp301_1	   
timedd0_3:
		  inc     tempd
		  mov     tempa,tempc
          or      tempa,tempd
		  cp      tempa,tempe
		  brlo    timedd0_4
		  clr     tempd
timedd0_4:
          cpi     tempd,$0a
		  brlo    timedd0_5    
          clr     tempd	        
timedd0_5:          
		  cpi     tempc,$00
		  brne    timedd0_6
		  cpi     tempd,$00
		  brne    timedd0_6
		  ldi     tempd,$01
timedd0_6:		  	
          or      tempc,tempd
		  sts     datesram,tempc
		  rjmp    keyp301_1		                           
;***************************************************
keyp3020:
          sbrs    keybit,kmodebit 
          rjmp    keyp3020_on   
		  cbr     keybit,0b00001111
		  ret
keyp3020_on:           
          sbrs    keybit,kaddbit          
          rjmp    keyp302_1
		  cbr     keybit,bit_5
		  cbr     keybit,kadd_bit
		  sbr     keybit,bit_6  
          rcall   lcdincmov0
          lds     tempc,daysram
		  inc     tempc
		  cpi     tempc,$08
		  brlo    keyp302_0
		  ldi     tempc,$01
keyp302_0:
		  sts     daysram,tempc
keyp302_1:
		  sbrs    keybit,bit4
		  rcall   kdisp302  
		  sbrs    keybit,bit5  
		  rcall   kdisp303
		  rcall   lcdmovtemp
		  ret  
;***************************************************
keyp310:
          ldi     tempc,$02
		  mov     maintab,tempc
		  sbr     buffbit,bit_0
          sbrs    keybit,ksetbit
		  rjmp    keyp310_on    
		  cbr     keybit,0b00001111
		  ret
keyp310_on:		   
		  sbrs    keybit,bit5
		  rcall   kdisp310    
          sbrs    keybit,kmodebit          
          rjmp    keyp310_0
		  cbr     keybit,kmode_bit
		  rcall   lcdincmov
		  inc     keytab4
		  mov     tempc,keytab4
		  cpi     tempc,$08
		  brlo    keyp310_0
		  clr     keytab4
keyp310_0:
          sbrs    keybit,kaddbit          
          rjmp    keyp3103
		  cbr     keybit,kadd_bit 
		  sbr     keybit,bit_6
          rcall   lcdincmov0
		  ldi     tempb,$10		           
          mov     tempc,keytab3
		  cpi     tempc,$00
		  brne    keyp3100
		  ldi     yh,high(hr1sramh)
		  ldi     yl,low(hr1sramh)
          rjmp    keyp3102          
keyp3100:
		  cpi     tempc,$01
          brne    keyp3101
		  ldi     yh,high(hr2sramh)
		  ldi     yl,low(hr2sramh)
          rjmp    keyp3102
keyp3101:
		  ldi     yh,high(hr3sramh)
		  ldi     yl,low(hr3sramh)
keyp3102:
          ldi     zh,high(time_tab)
		  ldi     zl,low(time_tab)
		  add     zl,keytab4
		  adc     zh,clrtemp
		  ijmp   
time_tab:
          rjmp    htimeh0  ;0 
		  rjmp    htimel0  ;0

		  rjmp    mtimeh0  ;1
		  rjmp    mtimel0  ;1

		  rjmp    htimeh1  ;2
		  rjmp    htimel1  ;2

		  rjmp    mtimeh1  ;3
		  rjmp    mtimel1  ;3         
htimeh1:  
          sbiw    yl,$02
htimeh0:	   
          ld      tempc,y
          rcall   sethrh
		  st      y,tempc
		  rjmp    keyp3103
htimel1:
          sbiw    yl,$02
htimel0:          
          ld      tempc,y
          rcall   sethrl
		  st      y,tempc
		  rjmp    keyp3103
mtimeh1:
          sbiw    yl,$02
mtimeh0:
          sbiw    yl,$01
          ld      tempc,y
          rcall   setminh
		  st      y,tempc
          rjmp    keyp3103
mtimel1:
          sbiw    yl,$02
mtimel0:
          sbiw    yl,$01
		  ld      tempc,y
          rcall   setminl
		  st      y,tempc
keyp3103:
          rcall   kdisp3100
		  rcall   lcdmovtemp
		  ret 		                   
;***************************************************
lcdincmov:
		  ldi     tempc,40
		  rjmp    lcdincmov1
lcdincmov0:		      
          ldi     tempc,$01
lcdincmov1:
		  sts     lcdincsram0,tempc
		  clr     tempc
		  sts     lcdincsram1,tempc
		  cbr     buffbit,bit_1
          ret
;***************************************************
writeds1302: 
          mov     tempc,keytab3
		  cpi     tempc,$00
		  brne    wrds0 
		  ldi     tempd,$84
          ldi     zh,high(hrsram)
		  ldi     zl,low(hrsram)
          mov     tempc,keytab4
		  cpi     tempc,$02
		  brlo    wrds2
		  sbiw    zl,$01
		  ldi     tempd,$82
		  cpi     tempc,$04
		  brlo    wrds2
		  sbiw    zl,$01
		  ldi     tempd,$80
          rjmp    wrds2
;***************************************************
wrds0:
          cpi     tempc,$01
		  brne    wrds1
		  ldi     tempd,$8c
          ldi     zh,high(yearsram)
		  ldi     zl,low(yearsram)
          mov     tempc,keytab4
		  cpi     tempc,$02          
		  brlo    wrds2
		  ldi     tempd,$88
		  sbiw    zl,$02
		  cpi     tempc,$04
		  brlo    wrds2
		  sbiw    zl,$01
		  ldi     tempd,$86
          rjmp    wrds2
;***************************************************
wrds1:
		  ldi     zh,high(daysram)
		  ldi     zh,low(daysram)
          ldi     tempd,$8a
wrds2:
          sts     command,tempd
;          ldi     tempf,$01     
          rcall   Send_Byte   
		  ret            
;**************************************************
readds1302:
          lds     tempc,Tdelay
  		  dec     tempc
		  sts     Tdelay,tempc
		  brne    Rd_Ret	
reds1302:		  	 
          ldi     tempc,$bf        ;命令字节为 BFh
          sts     command,tempc		   
          ldi     zh,high(srcsram) 
          ldi     zl,low(srcsram)
	      ldi     tempf,$07      
          rcall   Receive_Byte  
Rd_Ret:
		  ret                         
;**************************************************
Write_Enable:
          ldi      tempc,$8e        ;Command
		  ldi      tempd,$00        ;comdata
Write_0:
		  sts      command,tempc
		  sts      ComData,tempd
;          ldi      tempf,$01        ;ByteCnt
          ldi      zh,high(ComData)
		  ldi      zl,low(ComData)
          rcall    Send_Byte
          ret                        
 ;**************************************************
;Write_Disable:
;          ldi      tempc,$8e    ;Command
;          ldi      tempd,$80    ;comdata
;          rjmp     Write_0
;**************************************************
write_tcs:
          ldi      tempc,$90    ;Command
		  ldi      tempd,$a5    ;comdata
          rjmp     Write_0
;**************************************************
EEPROM_WR:
       	  rcall	   EEPROM_RD
	      cp	   tempc,tempd	
	      brne	   EEPROM_WR1
	      ret	
EEPROM_WR1:	
	      sbic	   EECR,EEWE	 	      rjmp	   EEPROM_WR1	 
	      out	   EEARH,ZH	 	      out	   EEARL,ZL	 
	      out	   EEDR,tempc
	      sbi	   EECR,EEMWE
	      sbi	   EECR,EEWE	 
	      ret	 	 	 
;*********************************************
EEPROM_RD: 
	      sbic	   EECR,EEWE	 	      rjmp 	   EEPROM_RD	 
	      out	   EEARH,ZH	 	      out	   EEARL,ZL	
	      sbi	   EECR,EERE
	      in	   tempd,EEDR
	      ret	 	 	 
;*********************************************
rdtimemovlcd_d:
          ldi      xh,high(lcdsram1+6)
 		  ldi      xl,low(lcdsram1+6)
          ldi      yh,high(yeartemph+1)
		  ldi      yl,low(yeartemph+1)
          rjmp     srammovlcd_d2
srammovlcd_d0:
          ldi      yh,high(yearsram+1)
		  ldi      yl,low(yearsram+1)
          ldi      xh,high(lcdsram2+4)
 		  ldi      xl,low(lcdsram2+4)
		  ldi      tempe,$01
		  rjmp     srammovlcd_d20	  		  		           
srammovlcd_d: 
          ldi      xh,high(lcdsram1+3)
 		  ldi      xl,low(lcdsram1+3)
srammovlcd_d1:		  		     
          ldi      yh,high(yearsramh+1)
		  ldi      yl,low(yearsramh+1)
srammovlcd_d2:
          ldi      tempe,$02
srammovlcd_d20:
		  rcall    srammovlcd0
		  sbiw     yl,$01		            
		  ldi      tempe,$01
		  rcall    srammovlcd0
		  ldi      tempe,$01
		  rcall    srammovlcd0
          ret
rdtimemovlcd_t:
          ldi      xh,high(lcdsram2+7)
 		  ldi      xl,low(lcdsram2+7)
          ldi      yh,high(hrtemp+1)
		  ldi      yl,low(hrtemp+1)
          rjmp     srammovlcd_t0
srammovlcd_t: 
          ldi      yh,high(hrsram+1)
		  ldi      yl,low(hrsram+1)
srammovlcd_t1:
          ldi      xh,high(lcdsram2+4)
 		  ldi      xl,low(lcdsram2+4)
srammovlcd_t0:
		  ldi      tempe,$01
		  rcall    srammovlcd0
          ldi      tempe,$01
		  rcall    srammovlcd0
          ldi      tempe,$01
		  rcall    srammovlcd0
		  ret
 srammovlcd0:		   
		  ld       tempc,-y
		  mov      tempd,tempc
		  swap     tempc
		  andi     tempc,$0f
		  ldi      zh,high(lcdtab0*2)
		  ldi      zl,low(lcdtab0*2)
		  add      zl,tempc
		  adc      zh,clrtemp
		  lpm      tempc,z
		  st       x+,tempc
		  andi     tempd,$0f
		  ldi      zh,high(lcdtab0*2)
		  ldi      zl,low(lcdtab0*2)
		  add      zl,tempd
		  adc      zh,clrtemp
		  lpm      tempc,z
		  st       x+,tempc
          dec      tempe
		  brne     srammovlcd0
		  adiw     xl,$01
          ret
;************************************************** 
lcdmovtemp:
		  ldi      yh,high(lcdtemp)
		  ldi      yl,low(lcdtemp)
		  ldi      zh,high(lcdsram2)
		  ldi      zl,low(lcdsram2)
		  ldi      tempd,16
		  rjmp     movlcdon		            
movlcd:		           
		  mov      tempc,buffbit
          sbr      buffbit,bit_1
		  sbrc     tempc,bit1
		  cbr      buffbit,bit_1
          sbrs     buffbit,bit1
		  rjmp     lcdoff
movlcdon0:
		  ldi      zh,high(lcdtemp)
		  ldi      zl,low(lcdtemp)
		  ldi      yh,high(lcdsram2)
		  ldi      yl,low(lcdsram2)
		  ldi      tempd,16
movlcdon:
		  ld       tempc,z+
		  st       y+,tempc
		  dec      tempd
		  brne     movlcdon

⌨️ 快捷键说明

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