avr flash
The Universal Synchronous and Asynchronous serial Receiver and Transmitter (USART) is a highly flexible serial communication device. The main features are:
通用同步和异步串行接收器和发送器(USART)是一种高度灵活的串行通信设备。 主要特点是:
Full Duplex Operation (Independent Serial Receive and Transmit Registers)
全双工操作(独立的串行接收和发送寄存器)
Asynchronous or Synchronous Operation
异步或同步操作
Master or Slave Clocked Synchronous Operation
主或从时钟同步操作
High-Resolution Baud Rate Generator
高分辨率波特率发生器
Supports Serial Frames with 5, 6, 7, 8, or 9 Data Bits and 1 or 2 Stop Bits
支持具有5、6、7、8或9个数据位和1或2个停止位的串行帧
Odd or Even Parity Generation and Parity Check Supported by Hardware
硬件支持奇偶校验生成和奇偶校验
Data Overrun Detection
数据溢出检测
Framing Error Detection
帧错误检测
Noise Filtering Includes False Start Bit Detection and Digital Low Pass Filter
噪声过滤包括错误的起始位检测和数字低通滤波器
Three Separate Interrupts on TX Complete, TX Data Register Empty, and RX Complete
TX完成,TX数据寄存器为空和RX完成的三个独立中断
Multi-processor Communication Mode
多处理器通讯模式
Double Speed Asynchronous Communication Mode
双速异步通讯模式
These are some of the features of USART, we would now lean to create a program in which we would use Bluetooth technology to open and close a LED bulb. In our program, we would take a variable X, such that if X=A our bulb will glow and if X=B the bulb will stop glowing.
这些是USART的一些功能 ,我们现在倾向于创建一个程序,在该程序中,我们将使用蓝牙技术打开和关闭LED灯泡。 在我们的程序中,我们将使用变量X ,使得如果X = A ,则灯泡将发光,如果X = B,则灯泡将停止发光。
In the similar we can also use a fan instead of LED, then we would be controlling our Fan to start or stop.
同样,我们也可以使用风扇代替LED,然后控制风扇启动或停止。
Program:
程序:
</ s> </ s> </ s>#include <avr/io.h>
void usart_string(char*);
int main(void)
{
char x;
DDRA = 0x01;
UBRRL= 51;
UCSRB= 0x18;
UCSRC= 0x86;
usart_string("Sam");
while(1)
{
while((UCSRA&(1<<RXC))==0);
x=UDR;
if(x=='A')
{
PORTA=0x01;
}
else if(x=='B')
{
PORTA=0x00;
}
}
}
void usart_string(char*p)
{
while(*p!='\0')
{
UDR=*p;
while((UCSRA&(1<<TXC))==0);
UCSRA|=1<<TXC;
p++;
}
}
Explanation:
说明:
Write all the header files as written above.
像上面那样写所有的头文件。
Take a variable X which will decide whether our bulb will be ON or OFF.
取一个变量X来决定我们的灯泡是开还是关 。
DDRA=0x01 indicates that the Led bulb is connected.
DDRA = 0x01指示LED灯泡已连接。
UBRRL=51; indicates that the baud rate is set to 9600.
UBRRL = 51; 表示波特率设置为9600 。
UCSRB=0x18 means Rx and Tx are enabled.
UCSRB =为0x18装置R X和T X被启用。
The usart_string will print the word written inside it.
usart_string将打印其中写入的单词。
Inside the while loop, we have written our bulb glowing condition such that when A is received the LED will glow and when B is received the LED bulb will stop glowing.
在while循环内,我们编写了灯泡发光条件,以便当接收到A时LED发光,而当接收到B时LED灯泡停止发光。
BAUD RATE
波特率
It is the rate at which the information is processed/transferred to the communication channel.
它是信息被处理/传输到通信通道的速率。
Calculation of BAUD RATE
波特率的计算
Where, fOSC is "System Oscillator Clock Frequency".
其中, fOSC是“系统振荡器时钟频率” 。
Simulation:
模拟:
Explanation:
说明:
Select the following components:
选择以下组件:
- Atmega16
- LED Red
- From virtual instruments mode select a VIRTUAL TERMINAL
Add the components as shown in the figure.
如图所示添加组件。
Double click on ATmega16 and make its speed as 8000000 and upload the hex file in it.
双击ATmega16,使其速度达到8000000,并在其中上传十六进制文件。
When we will start the simulation a screen will appear that would be our simulation for a Bluetooth screen.
当我们开始仿真时,将出现一个屏幕,该屏幕将是我们对蓝牙屏幕的仿真。
Typing A will glow the bulb and typing B will stop the bulb from glowing.
键入A将使灯泡发光,键入B将使灯泡停止发光。
翻译自: https://www.includehelp.com/embedded-system/usart-home-automation.aspx
avr flash