找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

帖子
查看: 3405|回復(fù): 0
打印 上一主題 下一主題
收起左側(cè)

bascom avr版熱電偶TCK+AD8495+ADC測溫

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
本帖最后由 taotie 于 2020-9-3 13:13 編輯



rem Main.bas file generated by New Project wizard
rem
rem Created:   周二 8月 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()
'配置單模式和自動預(yù)分頻器設(shè)置

'單模式必須與GETADC()函數(shù)一起使用

'預(yù)分頻器將內(nèi)部時(shí)鐘除以2、4、8、16、32、64或128

'因?yàn)锳DC需要一個(gè)50-200千赫的時(shí)鐘

'自動功能將選擇可能的最高時(shí)鐘頻率
Config Adc = Free , Prescaler = Auto , Reference = avcc                               'Internal
'*******************OLED配置*********************************************************************************
Config Scl = Portc.5                                                           ' 用I2C引腳Scl = Portc.5 ,Sda = Portc.4
Config Sda = Portc.4
Config Twi = 400000                                                             ' i2c 的速度

I2cinit
$lib "i2c_twi.lbx"                                                                        ' 不使用模擬I2c的軟件,而是使用twi
$lib "glcdSSD1306-I2C.lib"                                                        ' 用glcdSSD1306-I2C庫替換默認(rèn)庫要添加在bascom avr庫中

#if _build < 20784
Dim ___lcdrow As Byte , ___lcdcol As Byte                                ' 老版本變量格式進(jìn)行編譯
#endif

Config Graphlcd = Custom , Cols = 128 , Rows = 64 , Lcdname = "SSD1306"   '配置圖形顯示器

'*********現(xiàn)在給芯片供電*********************
On ADC Adc_isr Nosave    'Nosave指定的中斷發(fā)生時(shí)執(zhí)行子程序。
Enable ADC
Enable Interrupts


'*******變量***********************
Dim W As long , Channel As Byte
Dim i As long
Dim d As string*5
Channel = 0


'************主程序************************
Do
  Channel = 0                    '現(xiàn)在從通道0讀取A/D值
  '閑置將使微型計(jì)算機(jī)進(jìn)入睡眠狀態(tài)。.
  '一個(gè)中斷就會喚醒微型計(jì)算機(jī).

Start ADC
   Idle
nop
nop
Stop ADC
waitms 10
i=w*5000                                 '分度轉(zhuǎn)換
i=i/1023
i=i-1250
i=i/5
'**********誤差校準(zhǔn)*************
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'太煩。。。后面不管了
'************************************
d=str(i)                            '數(shù)值轉(zhuǎn)字符串
d= format(d, "+000")            '輸出結(jié)果格式化------覆蓋顯示模式避免顯示跳動

  Setfont Font12x16
  Lcdat 2, 2 , "Channel " ;": "; Channel
Lcdat 6, 2 ,"value";": "; d
Loop
End

Sub Adc_isr()
  $asm
    push r26                               '在堆棧上推送寄存器      STACK ← Rr
    push r27
    push r24
    in r24,SREG                                       '進(jìn)入 Por               Rd ← P
    push r24
    push r25
  $End Asm

  W = GetADC(Channel)

  $Asm
    pop r25                                     '從堆棧彈出寄存器             Rd ← STACK
    pop r24
    Out SREG,r24
    pop r24
    pop r27
    pop r26
  $end Asm
End Sub


$include "../Font12x16.font"   

評分

參與人數(shù) 1黑幣 +50 收起 理由
admin + 50 共享資料的黑幣獎勵(lì)!

查看全部評分

分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享淘帖 頂 踩
回復(fù)

使用道具 舉報(bào)

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規(guī)則

手機(jī)版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機(jī)教程網(wǎng)

快速回復(fù) 返回頂部 返回列表