bascom-avr語句簡潔易學,部分語句兼容VB、excel的VBA函數,部分程序可以參考移植學習。
下面用bascom-avr調試arduino板
一、
1、編譯
用bascom-avr打開實例inkey.bas,程序共18行,按F7編譯。
編譯.jpg (126.78 KB, 下載次數: 72)
下載附件
2021-5-2 23:41 上傳
程序運行過程:串口接收一個字節變量A,通過串口輸出接收的字符和對應的ASCII碼,接著判斷其是否是十進制27=十六進制1B=鍵盤ESC的ASCII碼,如果不是則繼續接收和輸出串口變量A,如果是27則串口輸出ASCII碼,進入只接收27后終止接收程序。(共接收3次27結束程序)
2、仿真
編譯后按F2進入仿真見面,按F5仿真運行,在串口窗口輸入字符,程序運行相應結果
仿真.png (82.72 KB, 下載次數: 107)
下載附件
2021-5-2 23:31 上傳
3、選擇寫固件軟件
選擇刷機程序.jpg (134.84 KB, 下載次數: 91)
下載附件
2021-5-2 23:53 上傳
4、設置寫固件軟件
設置刷機程序.jpg (112 KB, 下載次數: 79)
下載附件
2021-5-2 23:48 上傳
5、寫固件
刷機.jpg (123.23 KB, 下載次數: 77)
下載附件
2021-5-2 23:50 上傳
6、串口測試
串口調試.png (49.58 KB, 下載次數: 73)
下載附件
2021-5-2 23:50 上傳
源程序如下:- '------------BASCOM-AVR串口inkey實例----------------------------------------------
- 'name : inkey.bas
- 'copyright : (c) 1995-2020, MCS Electronics
- 'purpose : demo: INKEY , WAITKEY
- 'micro : Mega328p
- 'suited for demo : yes
- 'commercial addon needed : no
- '----------------初始化硬件配置--使用arduino開發板-------------------------------------------------------------
- $regfile = "m328pdef.dat" 'atmega328p硬件
- $crystal = 16000000 ' 16MHZ時鐘
- $baud = 19200 ' 串口波特率
- $hwstack = 32 ' default use 32 for the hardware stack
- $swstack = 10 ' default use 10 for the SW stack
- $framesize = 40 ' default use 40 for the frame space
- '-----------------變量定義---------------------------------------------------------------
- Dim A As Byte , S As String * 2
- '-----程序運行----串口接收一個字節變量A,通過串口輸出接收的字符和對應的ASCII碼,接著判斷其是否是十進制27=十六進制1B=鍵盤ESC的ASCII碼,如果不是則繼續接收和輸出串口變量A,如果是27則串口輸出ASCII碼,進入只接收27后終止接收程序。(共接收3次27結束串口接收程序)
- Do
- A = Inkey() '從串口獲得ASCII變量’get ascii value from serial port
- 's = Inkey()
- If A > 0 Then
- '------循環判斷如果大于0則輸出字符和對應的ASCII碼,如果是27則停止循環接收----------------------------------------------------------------------- 'we got something
- Print Chr(a);" ASCII code " ; A ; " from serial"
- End If
- Loop Until A = 27 '是27則停止循環接收(直到按下ESC)
- A = Waitkey() '等待接收到字符
- 's = waitkey()
- Print Chr(a) '串口輸出字符
- 'wait until ESC is pressed
- Do ' 循環接收=27則結束程序
- Loop Until Inkey() = 27
- 'When you need to receive binary data and the bibary value 0 ,
- 'you can use the IScharwaiting() function.
- 'This will return 1 when there is a char waiting and 0 if there is no char waiting.
- 'You can get the char with inkey or waitkey then.
- '-----------------程序結束-----------------------------------------------------------------
- End
復制代碼
全部資料51hei下載地址:
inkey源程序.rar
(1.13 KB, 下載次數: 7)
2021-5-2 23:55 上傳
點擊文件名下載附件
源程序 下載積分: 黑幣 -5
|