找回密碼
 立即注冊(cè)

QQ登錄

只需一步,快速開始

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

用bascom-avr調(diào)試arduino板

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
bascom-avr語(yǔ)句簡(jiǎn)潔易學(xué),部分語(yǔ)句兼容VB、excel的VBA函數(shù),部分程序可以參考移植學(xué)習(xí)。
下面用bascom-avr調(diào)試arduino板
一、
1、編譯
用bascom-avr打開實(shí)例inkey.bas,程序共18行,按F7編譯。


程序運(yùn)行過(guò)程:串口接收一個(gè)字節(jié)變量A,通過(guò)串口輸出接收的字符和對(duì)應(yīng)的ASCII碼,接著判斷其是否是十進(jìn)制27=十六進(jìn)制1B=鍵盤ESC的ASCII碼,如果不是則繼續(xù)接收和輸出串口變量A,如果是27則串口輸出ASCII碼,進(jìn)入只接收27后終止接收程序。(共接收3次27結(jié)束程序)
2、仿真
編譯后按F2進(jìn)入仿真見面,按F5仿真運(yùn)行,在串口窗口輸入字符,程序運(yùn)行相應(yīng)結(jié)果

3、選擇寫固件軟件


4、設(shè)置寫固件軟件


5、寫固件


6、串口測(cè)試


源程序如下:
  1. '------------BASCOM-AVR串口inkey實(shí)例----------------------------------------------
  2. 'name                     : inkey.bas
  3. 'copyright                : (c) 1995-2020, MCS Electronics
  4. 'purpose                  : demo: INKEY , WAITKEY
  5. 'micro                    : Mega328p
  6. 'suited for demo          : yes
  7. 'commercial addon needed  : no
  8. '----------------初始化硬件配置--使用arduino開發(fā)板-------------------------------------------------------------

  9. $regfile = "m328pdef.dat"                                     'atmega328p硬件
  10. $crystal = 16000000                                          ' 16MHZ時(shí)鐘
  11. $baud = 19200                                               ' 串口波特率
  12. $hwstack = 32                                               ' default use 32 for the hardware stack
  13. $swstack = 10                                               ' default use 10 for the SW stack
  14. $framesize = 40                                             ' default use 40 for the frame space
  15. '-----------------變量定義---------------------------------------------------------------
  16. Dim A As Byte , S As String * 2
  17. '-----程序運(yùn)行----串口接收一個(gè)字節(jié)變量A,通過(guò)串口輸出接收的字符和對(duì)應(yīng)的ASCII碼,接著判斷其是否是十進(jìn)制27=十六進(jìn)制1B=鍵盤ESC的ASCII碼,如果不是則繼續(xù)接收和輸出串口變量A,如果是27則串口輸出ASCII碼,進(jìn)入只接收27后終止接收程序。(共接收3次27結(jié)束串口接收程序)
  18. Do
  19.    A = Inkey()                                              '從串口獲得ASCII變量’get ascii value from serial port
  20.    's = Inkey()
  21.    If A > 0 Then
  22.       '------循環(huán)判斷如果大于0則輸出字符和對(duì)應(yīng)的ASCII碼,如果是27則停止循環(huán)接收-----------------------------------------------------------------------                                             'we got something
  23.       Print Chr(a);" ASCII code " ; A ; " from serial"
  24.    End If
  25. Loop Until A = 27                                           '是27則停止循環(huán)接收(直到按下ESC)

  26. A = Waitkey()                                               '等待接收到字符
  27. 's = waitkey()
  28. Print Chr(a)                                                '串口輸出字符

  29. 'wait until ESC is pressed
  30. Do                          ' 循環(huán)接收=27則結(jié)束程序
  31. Loop Until Inkey() = 27

  32. 'When you need to receive binary data and the bibary value 0 ,
  33. 'you can use the IScharwaiting() function.
  34. 'This will return 1 when there is a char waiting and 0 if there is no char waiting.
  35. 'You can get the char with inkey or waitkey then.
  36. '-----------------程序結(jié)束-----------------------------------------------------------------
  37. End
復(fù)制代碼

全部資料51hei下載地址:
inkey源程序.rar (1.13 KB, 下載次數(shù): 7)

評(píng)分

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

查看全部評(píng)分

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

使用道具 舉報(bào)

本版積分規(guī)則

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

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

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