程序:
rem Main.bas file generated by New Project wizard
rem
rem Created: 周二 5月 12 2020 TAOTIE
rem Processor: ATmega8
rem Compiler: BASCOM-AVR控制數(shù)字電位器AD5206仿真
rem Write your code here
$regfile = "m8def.dat"
$crystal = 8000000
Dim c As Byte '通道變量
Dim X As Byte '電阻變量
Config Pinb.2 = Output '寫入控制
Config Spi = Hard , Interrupt = Off , Data Order = Msb , Master = Yes , Polarity = Low , Phase = 0 , Clockrate = 128 , Noss = 1
Spiinit
'調(diào)整各通道滑臂在下方輸出電壓為0v
For C = 0 To 5
x= 0
Portb.2 = 0 '寫入
Spiout c, 1 '寫入通道
Spiout X , 1 '寫入電阻值
Portb.2 = 1 '寫入停止
Waitms 10
Next C
'頻道0--5循環(huán),上臂A--W電阻值由小變大
Do
'For C = 0 To 5
c=0
For x= 0 To 255 Step 51
Portb.2 = 0 '寫入
Spiout c, 1 '寫入通道
Spiout X , 1 '寫入電阻值
Portb.2 = 1 '寫入停止
Waitms 10
Next x