Bascom avr version thermocouple TCK+AD8495+ADC temperature measurement

Publisher:MysticalGlowLatest update time:2020-09-07 Source: 51heiKeywords:bascom  AD8495 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

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"   

Keywords:bascom  AD8495 Reference address:Bascom avr version thermocouple TCK+AD8495+ADC temperature measurement

Previous article:ATMEGA16 IO Ports Summary
Next article:PCA9685 PWM servo driver board 16-channel module IIC interface

Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号