bascom-avr语句简洁易学,部分语句兼容VB、excel的VBA函数,部分程序可以参考移植学习。
下面用bascom-avr调试arduino板
一、
1、编译
用bascom-avr打开实例inkey.bas,程序共18行,按F7编译。
程序运行过程:串口接收一个字节变量A,通过串口输出接收的字符和对应的ASCII码,接着判断其是否是十进制27=十六进制1B=键盘ESC的ASCII码,如果不是则继续接收和输出串口变量A,如果是27则串口输出ASCII码,进入只接收27后终止接收程序。(共接收3次27结束程序)
2、仿真
编译后按F2进入仿真见面,按F5仿真运行,在串口窗口输入字符,程序运行相应结果
3、选择写固件软件
4、设置写固件软件
5、写固件
6、串口测试
源程序如下:- '------------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)
|