|
編譯環(huán)境:bascom avr+Proteus8.9
屏幕截圖(30).png (169.06 KB, 下載次數(shù): 113)
下載附件
2020-6-15 16:14 上傳
單片機(jī)源程序如下:
- rem Main.bas file generated by New Project wizard
- rem
- rem Created: 周二 6月 2 2020 TAOTIE
- rem Processor: ATmega8
- rem Compiler: BASCOM-AVR
- rem Write your code here
- $regfile = "m8def.dat"
- $crystal = 8000000
- '$baud = 9600
- $hwstack = 32
- $swstack = 30
- $framesize = 40
- Config Scl = Portc.5 ' 用I2C引腳Scl = Portc.5 ,Sda = Portc.4
- Config Sda = Portc.4
- Config Twi = 400000 ' i2c 的速度
- Ddrc.3 = 0 '配置端口方向輸入(啟動(dòng)鍵)
- Portc.3 = 1 '上拉電阻有效
-
- 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" '配置圖形顯示器
- DIM X AS bit '時(shí)間閘門標(biāo)志
- dim jisu as word '脈沖計(jì)數(shù)變量
- 'Config Timer1 = Counter , Edge = Rising 'Timer1工作在計(jì)數(shù)方式上升沿有效
- Config Timer1 = Counter , Edge = Falling 'Timer1工作在計(jì)數(shù)方式下降沿有效
- Config Timer0 = Timer , Prescale = 8 'Timer0工作在計(jì)時(shí)方式預(yù)分頻=8
- On Ovf0 Tim0_isr '計(jì)時(shí)器中斷服務(wù)標(biāo)號(hào)Tim0_isr
- tcnt0=&h06 '從6開始計(jì)250次 中斷1次 250us
- Enable Timer0 '啟用計(jì)時(shí)器中斷
- Enable Interrupts
-
- do '外循環(huán)
- BITWAIT pinc.3, RESET '等待pinc.3置零啟動(dòng)運(yùn)行
- jisu=0 '脈沖計(jì)數(shù)變量初始化
- x=0 '時(shí)間閘門標(biāo)志初始化
- stop Timer1 '停止計(jì)數(shù)計(jì)時(shí)
- stop Timer0
- Tcnt1 = 0 ' 計(jì)時(shí)計(jì)數(shù)寄存器初始為零
- Timer1 =0
-
-
- start Timer1 '啟動(dòng)Timer1
- start Timer0 '啟動(dòng)Timer0
- cls '清屏
- Do '內(nèi)循環(huán)
- Setfont font12x16
- Lcdat 2, 8 , "km/hr=" ;Tcnt1
- if x =1 then exit do '如果時(shí)間閘門標(biāo)志=1則跳出內(nèi)循環(huán)
-
-
- Loop
- loop '循環(huán)返回到外循環(huán)開始處
- end
- Tim0_isr:
- tcnt0=&h06 '進(jìn)入中斷先賦初值
- incr jisu '每次進(jìn)入脈沖計(jì)數(shù)變量加1’
- if jisu=9286 then '如果脈沖計(jì)數(shù)變量等于時(shí)間閘門需求時(shí)間閘門標(biāo)志=1
- x=1
- end if
- Return
- $include "../font12x16.font"
-
復(fù)制代碼
51hei.png (5.81 KB, 下載次數(shù): 114)
下載附件
2020-6-15 18:28 上傳
所有資料51hei提供下載:
計(jì)數(shù).zip
(38.26 KB, 下載次數(shù): 44)
2020-6-15 16:17 上傳
點(diǎn)擊文件名下載附件
下載積分: 黑幣 -5
|
|