标题: 再请教下 [打印本页] 作者: donny_y 时间: 2013-5-20 16:07 标题: 再请教下 dim a as word
dim b(4) as byte
a=9527
b(1)=a/1000
b(2)=a mod 1000
b(2)=b(2)/100
b(3)=a mod 100
b(3)=b(3)/10
b(4)=a mod 10
请问结果会是多少啊作者: donny_y 时间: 2013-5-20 16:19
其实我就是想把9527 拆开 为四个单独的数字 9,5,2,7 用来数码管显示
请问怎么实现作者: donny_y 时间: 2013-5-20 16:23
Dim A As Integer
Dim B(4) As Integer
A = 9527
B(1) = A / 1000
B(2) = A Mod 1000
B(2) = B(2) / 100
B(3) = A Mod 100
B(3) = B(3) / 10
B(4) = A Mod 10
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
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 = 9527
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