📄 adcu812.bas
字号:
'---------------------------------------------------------------------
' ADCU812.bas (c) 2000 MCS Electronics
' Note that the support for this chip is untested
' Any feedback appreciated!
'---------------------------------------------------------------------
'Use this dat file
$regfile = "812.dat"
'configure ADC
Config Aduc812 = Adcon , Mode = Normal , Clock = 1 , Aquisition = 1 , Timer2 = Disabled , Extrig = Disabled
'configure DACS
Config Aduc812 = Dac , Mode = 12 , Range1 = Vref , Range0 = Vref , Clear0 = False , Sync = Enabled , Power0 = On , Power1 = Off
Declare Sub Write_ebyte
Declare Sub Read_ebyte
'dim variables
Dim Wdac As Word
Dim Adc As Word
Dim Eeadr As Word , Eebyte As Byte , Page As Word
'get value from adc channel 0
'note that simulator will halt until you make the adccon2 bit 4 zero.
'the AD converter needs the global interrupt bit set so set it from BASIC
Enable Interrupts ' needed by getad()
Adc = Getad(0)
Print Adc
Adc = Getad(1)
Print Adc
'enable dac0 by powering it on
Dac0.poweron
'0V to output of dac0
Dac0.clear
'put voltage into dacs
Dac0.value = 12
Dac1.value = 500
'dac0 was 0V but must work normal now
Dac0.normal
'and after setting the value(s) the dacs must be updated with the sync method
Dac.sync
'flash some leds
For Page = 1 To 10
P2 = 255
Wait 1
P2 = 0
Wait 1
Next
'the EEPROM is accessed via pages
'each page is 4 bytes
'to write 1 byte you need to write the whole 4 byte page
'assign eeadr with the address
'and eebyte with the value to write
Eeadr = 100 : Eebyte = 5 : Call Write_ebyte
Eeadr = 100 : Call Read_ebyte
Print Eebyte
End
Sub Write_ebyte
Page = Eeadr \ 4 'page
mov edarl,{page} ; page address
mov econ,#1 ; read 4 current bytes
mov econ,#5 ; erase page
Waitms 20 'wait 20 msecs
Page = Page * 4
Page = Eeadr - Page
If Page = 0 Then
mov edata1,{eebyte} ; data register to write
Elseif Page = 1 Then
mov edata2,{eebyte} ; data register to write
Elseif Page = 2 Then
mov edata3,{eebyte} ; data register to write
Else 'must be 3
mov edata4,{eebyte} ; data register to write
End If
mov econ,#2 ; write registers
End Sub
Sub Read_ebyte
Page = Eeadr \ 4 'page
mov edarl,{page} ; page address
mov econ,#1 ; read 4 current bytes
Page = Page * 4
Page = Eeadr - Page
If Page = 0 Then
mov {EEbyte},edata1 ; data register to read
Elseif Page = 1 Then
mov {eebyte},edata2 ; data register to read
Elseif Page = 2 Then
mov {eebyte},edata3 ; data register to read
Else 'must be 3
mov {eebyte},edata4 ; data register to read
End If
mov econ,#2 ; write registers
End Sub
End
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -