- 阅读权限
- 10
- UID
- 398
- 帖子
- 13
- 精华
- 0
- 注册时间
- 2013-5-18
- 在线时间
- 3 小时
- UID
- 398
- 帖子
- 13
- 精华
- 0
- 注册时间
- 2013-5-18
- 在线时间
- 3 小时
|
本帖最后由 donny_y 于 2013-5-27 12:17 编辑
$regfile = "m8def.dat"
$crystal = 1000000
Config Timer0 = Timer , Prescale = 8 '定义T0为定时器,8分频
On Timer0 T0_interrupt '定时器T0溢出指向T0_interrupt中断程序
Config Portd = Output 'PORTD口定义为输出,控制各段
Config Portc = Output 'PORTC口定义为输出,控制公共端
Leds Alias Portd 'PORTD口别名定义为Leds
Ledv Alias Portc 'PORTC口别名定义为Ledv
Dim Digital As Integer '定义变量
Dim Led_code(10)as Byte
Dim Led_seg(4)as Byte
Dim Led_disp(4) As Integer
Dim Temp As Byte
Dim I As Byte
Enable Interrupts '全局中断使能
Enable Timer0 '定时器中断使能
Restore Digital_code
For I = 1 To 10
Read Led_code(i)
Next
Restore Digtal_seg
For I = 1 To 4
Read Led_seg(i)
Next
Digital = 1
Do
Led_disp(1) = Digital / 1000
Led_disp(2) = Digital Mod 1000
Led_disp(2) = Led_disp(2) / 100
Led_disp(3) = Digital Mod 100
Led_disp(3) = Led_disp(3) / 10
Led_disp(4) = Digital Mod 10
Idle '单片机进入空闲状态
Loop
End
T0_interrupt: 'Timer0中断执行程序
Digital = Digital + 1
If Digital > 9999 Then Digital = 0
I = I + 1
If I < 5 Then
Ledv = &H00
Leds = &HFF
Leds = Lookup(led_disp(i) , Digital_code)
Ledv = Led_seg(i)
Else
I = 0
End If
Return
Digital_code:
Data &B11000000 , &B11111001 , &B10100100 , &B10110000 , &B10011001
Data &B10010010 , &B10000010 , &B11111000 , &B10000000 , &B10010000
Digtal_seg:
Data &B00001000 , &B00000100 , &B00000010 , &B00000001 |
|