如题,代码如下:
$regfile = "attiny45.dat" '指定单片机型号
$crystal = 8000000 '指定频率
$hwstack = 2
$swstack = 8
$framesize = 24
Config Portb = Output '定义B口为输出
Config Portb.4 = Input '定义C.0口为输入
Config Adc = Single , Prescaler = Auto , Reference = Avcc '配置AD转换器
Enable Adc '使能AC转换器
Dim Leddig(10) As Byte
Dim I As Word , P As Integer , V As Word , B As Word , N As Word , M As Word
Dim K As Single , G As Byte , S As Long , A As Word , C As Byte
Latch Alias Portb.1
Config Spi = Soft , Dout = Portb.3 , Ss = None , Clock = Portb.0
Restore Leddata '读LED 显示位码(0-9)
For P = 1 To 10
Read Leddig(p)
Next
Do
A = 0
C = 1
For C = 1 To 64 '取64次adc的平均值
Start Adc
I = Getadc(2)
Stop Adc
A = I + A
Next
A = A / 64
S = A * 5000
K = S / 1023
A = K
A = A / 2 '设置最大量程为25V '
V = A / 1000 '千位
B = A / 100 '百位
N = A / 10 '十位
M = A Mod 10
Waitms 20
Spiinit '个位
P = M
Spiout Leddig(p + 1) , 1 '显示个位
P = N
If N > 9 Then
P = P Mod 10
End If
Spiout Leddig(p + 1) , 1
P = B
If B > 9 Then
P = P Mod 10
End If
Spiout Leddig(p + 1) , 1 '显示小数点
P = V
If V > 9 Then
P = P Mod 10
End If
Spiout Leddig(p + 1) , 1
Latch = 0 '使能显示
Waitus 10
Latch = 1
Loop
Leddata: 'LED数字码 (0-9)
Data &B00111111 , &B00000110 , &B01011011 , &B01001111 , &B01100110
Data &B01101101 , &B01111101 , &B00000111 , &B01111111 , &B01101111
注释掉的恢复了,可以了
上一篇:avr mega8 PWM 超声发射试验程序
下一篇:BASCOM AVR 版 RC5红外发射与接收遥控
- 热门资源推荐
- 热门放大器推荐
设计资源 培训 开发板 精华推荐
- ESP32C3实现一个NorFlash编程器、烧录器
- ADR445B 5 Vout 超低噪声、LDO XFET 电压基准的典型应用,带电流吸收器和电流源
- STM32F411-BOARD
- STEVAL-ISV020V1,用于 SPV1050 ULP 能量收集器和电池充电器的评估板 - 降压-升压配置
- NCV1117 1.0 A 低压降正可调稳压器的典型应用
- 550A-MATX-AP机箱
- LT3461AES6 演示板,升压转换器,Vin = 3V - 6V,Vout = 12V,(如果 Vin = 5V,Iout = 70mA)
- LTC6261HS6 SAR ADC 驱动器、运算放大器的典型应用
- 使用 NXP Semiconductors 的 MCZ33810EK 的参考设计
- LTC6990IDCB#TRMPBF 正交正弦波振荡器的典型应用。压控频率范围为 5Hz 至 20kHz,具有 1VP-P 恒定输出幅度