標(biāo)題: 用bascom-avr調(diào)試arduino板 [打印本頁(yè)]

作者: wu111111mi    時(shí)間: 2021-5-2 23:56
標(biāo)題: 用bascom-avr調(diào)試arduino板
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)入仿真見(jià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)





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