rem Main.bas file generated by New Project wizard
rem
rem Created: Tuesday, August 25, 2020 TAOTIE
rem Processor: ATmega8
rem Compiler: BASCOM-AVR
rem Write your code here
$RegFile = "m8def.dat"
$Crystal = 8000000
'$Baud = 19200
$HWstack = 40
$SWstack = 8
$FrameSize = 40
Declare Sub Adc_isr()
'Configure single mode and automatic prescaler settings
'Single mode must be used with the GETADC() function
'The prescaler divides the internal clock by 2, 4, 8, 16, 32, 64, or 128
'Because the ADC requires a 50-200 kHz clock
'The automatic function will select the highest possible clock frequency
Config Adc = Free , Prescaler = Auto , Reference = avcc 'Internal
'*******************OLED configuration****************************************************************************
Config Scl = Portc.5 ' Use I2C pin Scl = Portc.5, Sda = Portc.4
Config Sda = Portc.4
Config Twi = 400000 ' i2c speed
I2cinit
$lib "i2c_twi.lbx" ' Do not use software to simulate I2c, but use twi
$lib "glcdSSD1306-I2C.lib" ' Replace the default library with glcdSSD1306-I2C library to be added in bascom avr library
#if _build < 20784
Dim ___lcdrow As Byte , ___lcdcol As Byte ' Compile with the old version variable format
#endif
Config Graphlcd = Custom , Cols = 128 , Rows = 64 , Lcdname = "SSD1306" 'Configure the Graphic Display
'*********Now power the chip************************
On ADC Adc_isr Nosave 'Nosave Execute the subroutine when the specified interrupt occurs.
Enable ADC
Enable Interrupts
'*******Variables***********************
Dim W As long , Channel As Byte
Dim i As long
Dim d As string*5
Channel = 0
'************Main Program************************
Do
Channel = 0 'Now read the A/D value from channel 0
'Idle will put the microcomputer to sleep. .
'An interrupt will wake up the microcomputer.
Start ADC
Idle
nop
nop
Stop ADC
waitms 10
i=w*5000 'Division conversion
i=i/1023
i=i-1250
i=i/5
'**********Error calibration**** *********
i=i-1
if i>10 then i=i+1
if i>73 then i=i-1
if i>124 then i=i-1
if i>139 then i =i+1
if i>=183 then i=i+1
if i>221 then i=i-1
if i>226 then i=i+1
if i>267 then i=i-1
if i>269 then i=i+1
if i>296 then i=i-1
if i>314 then i=i+1'Too annoying. . . No matter what happens later
'************************************
d=str(i) 'Convert the value to a character string
d = format(d, "+000") 'Output result formatting------override display mode to avoid display jumps
Setfont Font12x16
Lcdat 2, 2 , "Channel " ;": "; Channel
Lcdat 6, 2 ,"value";": "; d
Loop
End
Sub Adc_isr()
$asm
push r26 'Push register on stack STACK ← Rr
push r27
push r24
in r24,SREG 'Enter Por Rd ← P
push r24
push r25
$End Asm
W = GetADC(Channel)
$Asm
pop r25 'Pop register from stack Rd ← STACK
pop r24
Out SREG,r24
pop r24
pop r27
pop r26
$end Asm
End Sub
$include "../Font12x16.font"
Previous article:ATMEGA16 IO Ports Summary
Next article:PCA9685 PWM servo driver board 16-channel module IIC interface
- Popular Resources
- Popular amplifiers
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- CGD and Qorvo to jointly revolutionize motor control solutions
- CGD and Qorvo to jointly revolutionize motor control solutions
- Keysight Technologies FieldFox handheld analyzer with VDI spread spectrum module to achieve millimeter wave analysis function
- Infineon's PASCO2V15 XENSIV PAS CO2 5V Sensor Now Available at Mouser for Accurate CO2 Level Measurement
- Advanced gameplay, Harting takes your PCB board connection to a new level!
- Advanced gameplay, Harting takes your PCB board connection to a new level!
- A new chapter in Great Wall Motors R&D: solid-state battery technology leads the future
- Naxin Micro provides full-scenario GaN driver IC solutions
- Interpreting Huawei’s new solid-state battery patent, will it challenge CATL in 2030?
- Are pure electric/plug-in hybrid vehicles going crazy? A Chinese company has launched the world's first -40℃ dischargeable hybrid battery that is not afraid of cold
- Thank you for being my first leader in the workplace
- MicroPython now supports STM32L452
- MOS tube control shutdown problem
- Goodbye 2019, Hello 2020 + Review of my 2019
- MSP430 non-continuous IO parallel port output matrix keyboard
- [Shenzhen IC factory recruitment, starting from 400,000] Shenzhen IC factory, Fortune 500 company sincerely recruits digital IC practitioners
- Zero environment setup, the simplest QT interface programming Helloworld runs in the embedded Linux touch industrial tablet
- [Silicon Labs BG22-EK4108A Bluetooth Development Review] Four Programs Plus Button Development Steps
- USB driver-free camera hardware solution
- 【XMC4800 Relax EtherCAT Kit Review】+ Hardware Interpretation