刚学AVR想用MEGA16做过数显电源,用BASCOM-AVR编程
用八段数码管分辨显示四位数电压,四位数电流,BASCOM编程(感觉比较简单学)。
其凑八凑,凑足一个程序。
只是数显,东西到手了,上面原来那个程序很不行,闪烁很严重。于是修改了如下:
$regfile = "m16def.dat" '目标单片机为ATmega16
$crystal = 8000000 '系统时钟8兆
Config Timer1 = Timer , Prescale = 64 '使用定时器1,64分频
On Ovf1 Timer1_isr '启用定时器溢出中断
Config Adc = Single , Prescaler = Auto , Reference = Avcc '设置ADC为单次转换模式,采样频率系统设定,参考电压使用AVcc
Config Portb = Output '配置端口PortB输出
Config Portd = Output '配置端口PortD输出
Dim V As Word '定义ADC采集变量 V
Dim I As Word '定义ADC采集变量 I
Dim V1 As Integer , V2 As Integer , V3 As Integer , V4 As Integer '定义ADC采样变量V1为十位,V2为个位,V3为十分位,V4为百分
Dim I1 As Integer , I2 As Integer , I3 As Integer , I4 As Integer '定义ADC采样变量I1为个位,I2为十分位,I3为百分位,I4为千分位
Dim L(10) As Byte '定义字形数组
Dim T As Byte '定义计数,循环控制变量T
Dim Dx As Byte : Dx = 0 '定义计数,段选DX
Dim _change As Byte : _change = 0 '中断发生计数变量