標(biāo)題: avr單片機(jī)Proteus風(fēng)速計模型仿真 bascom源程序 [打印本頁]

作者: taotie    時間: 2020-6-15 16:18
標(biāo)題: avr單片機(jī)Proteus風(fēng)速計模型仿真 bascom源程序
編譯環(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                                                                    '配置端口方向輸入(啟動鍵)
  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                          '時間閘門標(biāo)志
  27. dim jisu as word                         '脈沖計數(shù)變量


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

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

  33. Enable Timer0                                               '啟用計時器中斷
  34. Enable Interrupts              

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

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

  45.                            
  46. start Timer1                                                                    '啟動Timer1
  47. start Timer0                                                                    '啟動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                                     '如果時間閘門標(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)入脈沖計數(shù)變量加1’
  60. if jisu=9286 then                                  '如果脈沖計數(shù)變量等于時間閘門需求時間閘門標(biāo)志=1
  61. x=1                                                         
  62. end if
  63. Return

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

所有資料51hei提供下載:
計數(shù).zip (38.26 KB, 下載次數(shù): 44)

作者: 水淌    時間: 2021-5-6 20:47
哇,謝謝樓主,下載學(xué)習(xí)學(xué)習(xí)




歡迎光臨 (http://www.torrancerestoration.com/bbs/) Powered by Discuz! X3.1