找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 3344|回复: 1
收起左侧

avr单片机Proteus风速计模型仿真 bascom源程序

[复制链接]
ID:342822 发表于 2020-6-15 16:18 | 显示全部楼层 |阅读模式
编译环境:bascom avr+Proteus8.9
屏幕截图(30).png

单片机源程序如下:
  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库替换默认库要添加在bascom avr库中

  22. #if _build < 20784
  23. Dim ___lcdrow As Byte , ___lcdcol As Byte                                ' 老版本变量格式进行编译
  24. #endif

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



  26. DIM  X   AS  bit                          '时间闸门标志
  27. dim jisu as word                         '脉冲计数变量


  28. 'Config Timer1 = Counter , Edge = Rising                        'Timer1工作在计数方式上升沿有效
  29. Config Timer1 = Counter , Edge = Falling                           'Timer1工作在计数方式下降沿有效
  30. Config Timer0 = Timer , Prescale = 8                                   'Timer0工作在计时方式预分频=8

  31. On Ovf0 Tim0_isr                                                                    '计时器中断服务标号Tim0_isr
  32. tcnt0=&h06                                                                               '从6开始计250次 中断1次      250us                     

  33. Enable Timer0                                               '启用计时器中断
  34. Enable Interrupts              

  35.                                                                   
  36. do                                                                                         '外循环

  37. BITWAIT  pinc.3, RESET                                               '等待pinc.3置零启动运行  
  38. jisu=0                                                                               '脉冲计数变量初始化
  39. x=0                                                                                   '时间闸门标志初始化
  40. stop  Timer1                                                                   '停止计数计时
  41. stop  Timer0
  42.   Tcnt1 = 0                                                                      ' 计时计数寄存器初始为零
  43. Timer1 =0
  44.    

  45.                            
  46. start Timer1                                                                    '启动Timer1
  47. start Timer0                                                                    '启动Timer0

  48. cls                                                                                    '清屏

  49. Do    '内循环
  50. Setfont font12x16
  51. Lcdat 2, 8 , "km/hr=" ;Tcnt1                                                                              
  52.    if x =1 then  exit do                                     '如果时间闸门标志=1则跳出内循环
  53.   

  54. Loop
  55. loop                                                                                  '循环返回到外循环开始处
  56. end

  57. Tim0_isr:
  58. tcnt0=&h06                                             '进入中断先赋初值
  59. incr jisu                                                      '每次进入脉冲计数变量加1’
  60. if jisu=9286 then                                  '如果脉冲计数变量等于时间闸门需求时间闸门标志=1
  61. x=1                                                         
  62. end if
  63. Return

  64. $include  "../font12x16.font"
  65.                                                    
复制代码
51hei.png
所有资料51hei提供下载:
计数.zip (38.26 KB, 下载次数: 43)
回复

使用道具 举报

ID:906376 发表于 2021-5-6 20:47 | 显示全部楼层
哇,谢谢楼主,下载学习学习
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表