找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 4090|回復(fù): 1
打印 上一主題 下一主題
收起左側(cè)

avr單片機(jī)Proteus風(fēng)速計(jì)模型仿真 bascom源程序

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
編譯環(huán)境:bascom avr+Proteus8.9


單片機(jī)源程序如下:
  1. rem Main.bas file generated by New Project wizard
  2. rem
  3. rem Created:   周二 6月 2 2020                 TAOTIE
  4. rem Processor: ATmega8
  5. rem Compiler:  BASCOM-AVR

  6. rem Write your code here

  7. $regfile = "m8def.dat"                                 
  8. $crystal = 8000000                                       
  9. '$baud = 9600                                            
  10. $hwstack = 32                                            
  11. $swstack = 30                                             
  12. $framesize = 40   
  13. Config Scl = Portc.5                                                           ' 用I2C引腳Scl = Portc.5 ,Sda = Portc.4
  14. Config Sda = Portc.4
  15. Config Twi = 400000                                                             ' i2c 的速度  


  16.   Ddrc.3 =  0                                                                    '配置端口方向輸入(啟動(dòng)鍵)
  17. Portc.3 =  1                                                                     '上拉電阻有效
  18.                                                                                  
  19. I2cinit
  20. $lib "i2c_twi.lbx"                                                                        ' 不使用模擬I2c的軟件,而是使用twi
  21. $lib "glcdSSD1306-I2C.lib"                                                        ' 用glcdSSD1306-I2C庫替換默認(rèn)庫要添加在bascom avr庫中

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

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



  26. DIM  X   AS  bit                          '時(shí)間閘門標(biāo)志
  27. dim jisu as word                         '脈沖計(jì)數(shù)變量


  28. 'Config Timer1 = Counter , Edge = Rising                        'Timer1工作在計(jì)數(shù)方式上升沿有效
  29. Config Timer1 = Counter , Edge = Falling                           'Timer1工作在計(jì)數(shù)方式下降沿有效
  30. Config Timer0 = Timer , Prescale = 8                                   'Timer0工作在計(jì)時(shí)方式預(yù)分頻=8

  31. On Ovf0 Tim0_isr                                                                    '計(jì)時(shí)器中斷服務(wù)標(biāo)號(hào)Tim0_isr
  32. tcnt0=&h06                                                                               '從6開始計(jì)250次 中斷1次      250us                     

  33. Enable Timer0                                               '啟用計(jì)時(shí)器中斷
  34. Enable Interrupts              

  35.                                                                   
  36. do                                                                                         '外循環(huán)

  37. BITWAIT  pinc.3, RESET                                               '等待pinc.3置零啟動(dòng)運(yùn)行  
  38. jisu=0                                                                               '脈沖計(jì)數(shù)變量初始化
  39. x=0                                                                                   '時(shí)間閘門標(biāo)志初始化
  40. stop  Timer1                                                                   '停止計(jì)數(shù)計(jì)時(shí)
  41. stop  Timer0
  42.   Tcnt1 = 0                                                                      ' 計(jì)時(shí)計(jì)數(shù)寄存器初始為零
  43. Timer1 =0
  44.    

  45.                            
  46. start Timer1                                                                    '啟動(dòng)Timer1
  47. start Timer0                                                                    '啟動(dòng)Timer0

  48. cls                                                                                    '清屏

  49. Do    '內(nèi)循環(huán)
  50. Setfont font12x16
  51. Lcdat 2, 8 , "km/hr=" ;Tcnt1                                                                              
  52.    if x =1 then  exit do                                     '如果時(shí)間閘門標(biāo)志=1則跳出內(nèi)循環(huán)
  53.   

  54. Loop
  55. loop                                                                                  '循環(huán)返回到外循環(huán)開始處
  56. end

  57. Tim0_isr:
  58. tcnt0=&h06                                             '進(jìn)入中斷先賦初值
  59. incr jisu                                                      '每次進(jìn)入脈沖計(jì)數(shù)變量加1’
  60. if jisu=9286 then                                  '如果脈沖計(jì)數(shù)變量等于時(shí)間閘門需求時(shí)間閘門標(biāo)志=1
  61. x=1                                                         
  62. end if
  63. Return

  64. $include  "../font12x16.font"
  65.                                                    
復(fù)制代碼

所有資料51hei提供下載:
計(jì)數(shù).zip (38.26 KB, 下載次數(shù): 44)
分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏2 分享淘帖 頂 踩
回復(fù)

使用道具 舉報(bào)

沙發(fā)
ID:906376 發(fā)表于 2021-5-6 20:47 | 只看該作者
哇,謝謝樓主,下載學(xué)習(xí)學(xué)習(xí)
回復(fù)

使用道具 舉報(bào)

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

本版積分規(guī)則

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

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

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