您当前的位置:五五电子网电子知识单片机-工控设备AVR单片机简易带1/100秒的24小时制时钟 正文
简易带1/100秒的24小时制时钟

简易带1/100秒的24小时制时钟

点击数:7109 次   录入时间:03-04 11:41:11   整理:http://www.55dianzi.com   AVR单片机
display: 
   clr r0 
   ser temp               ;temp = 0x11111111 
   out portc,temp         ;关显示,去消影和拖尾作用 
   ldi yl,low(display_buff) 
   ldi yh,high(display_buff)   ;Y寄存器取得显示缓冲单元首指针 
   add yl,position         ;加上要显示的位值 
   adc yh,r0               ;加上低位进位 
   ld temp,y               ;temp中为要显示的数字 
    
   clr r0 
   ldi zl,low(led_7 * 2) 
   ldi zh,high(led_7 * 2)      ;Z寄存器取得7段码组的首指针 
   add zl,temp            ;加上要显示的数字 
   adc zh,r0               ;加上低位进位    
   lpm               ;读对应七段码到R0中 
   out porta,r0            ;LED段码输出 

   mov r0,p_temp 
   com r0, 
   out portc,r0         ;输出位控制字,完成LED一位的显示 
    
   inc position         ;调整到下一次显示位 
   lsl p_temp 
   cpi position,0x08 
   brne display_ret 
   ldi position,0x00 
   ldi p_temp,0x01 
display_ret: 
   ret 

;时钟时间调整,加0.01秒 
time_add: 
      ldi xl,low(time_buff)   ; 
      ldi xh,high(time_buff)   ;X寄存器为时钟单元首指针 
      rcall dhm3         ;ms单元加1调整 
      cpi temp,100      ; 
      brne   time_add_ret   ;未到100ms返回 
      rcall dhm         ;秒单元加1调整 
      cpi temp,60 
      brne   time_add_ret   ;未到60秒返回 
      rcall dhm         ;分单元加1调整 
      cpi temp,60 
      brne time_add_ret      ;未到60分返回 
      rcall dhm         ;时单元加1调整 
      cpi temp,24 
      brne time_add_ret         ;未到24时返回 
      clr temp 
      st x,temp            ;到24时,时单元清另 
time_add_ret: 
      ret 

;低段时间清零,高段时间加1 
dhm:  clr temp         ;当前时段清零 
dhm1: st  x+,temp         ;当前时段清零,X寄存器指针加一 
dhm3: ld  temp,x         ;取出新时段数据 
      inc temp             ;加一  
dhm2: st x,temp         ;并将调整结果送回 
      ret 

;将时钟单元数据送LED显示缓冲单元中 
put_t2d: 
   ldi xl,low(time_buff)      ; 
   ldi xh,high(time_buff)      ;X寄存器时钟单元首指针 
   ldi yl,low(display_buff) 
   ldi yh,high(display_buff)   ;Y寄存器显示缓冲单元首指针 
   ldi count,4            ;循环次数 = 4 
loop: 
   clr temp1
   ld   temp,x+            ;读一个时间单元 
loop1:
   cpi temp,10
   brlo loop2              ;<10转
   inc temp1
   subi temp,10            
   rjmp loop1
loop2:
   st y+,temp            ;写入2个显示单元 
   st y+,temp1         ;低位BCD码在前,高位在后 
   dec   count 
   brne   loop         ;4个时间单元->8个显示单元 
   ret 

;T1时钟溢出中断服务 
time1_ovf: 
   in int,sreg 
   push int            ;保护状态寄存器 
    
   ldi int,0xff         ;T1初始值设定,2ms中断一次 
   out tcnt1h,int 
   ldi int,0x83 
   out tcnt1l,int 
    
   inc count_10ms         ;10ms计数器加一 
   ldi flag_2ms,0x01         ;置2ms标志到 
    
pop int 
   out sreg,   int         ;恢复状态寄存器 
   reti                  ;中断返回       
    
.CSEG               ;LED七段码表,定义在Flash程序空间 
led_7:               ;7段码表 
.db 0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07 
.db 0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71    

;字 PA7 PA6 PA5 PA4 PA3 PA2 PA1 PA0 共阴极 共阳极 
;   h   g   f   E   d   c   b   a       
;0   0   0   1   1   1   1   1   1   3FH      C0H 
;1   0   0   0   0   0   1   1   0   06H      F9H 
;2   0   1   0   1   1   0   1   1   5BH      A4H 

上一页  [1] [2] [3]  下一页


本文关键字:暂无联系方式AVR单片机单片机-工控设备 - AVR单片机

《简易带1/100秒的24小时制时钟》相关文章>>>