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