avr uart打印_AVR | 在16x2 LCD上打印HELLO WORLD
avr uart打印
We would learn the connection to the LCD first as the connections is a bit complex and here we are using an 8-bit LCD.
我們將首先學習到LCD的連接,因為連接有點復雜,這里我們使用的是8位LCD 。
Simulation
模擬
Explanation
說明
Search these devices from the device selection menu:
從設備選擇菜單中搜索以下設備:
- ATmega16
- LM016L (It’s a 16*2 Alphanumeric LCD)
- One Power Terminal
- One Ground terminal
Connect the power terminal from the VDD and VEE of the LCD.
從LCD的VDD和VEE連接電源端子。
Connect the Enable pin (E) and VSS pin to the ground terminal.
將使能引腳(E)和VSS引腳連接到接地端子。
Double click on the Power terminal and write +5V in its properties.
雙擊電源端子,并在其屬性中寫入+ 5V 。
Connect the R/S and E pin to the PC0 and PC1 of the ATmega16.
將R / S和E引腳連接到ATmega16的PC0和PC1 。
The next step would be to debug the HEX file in the ATmega16.
下一步將是調試ATmega16中的HEX文件。
Now after all the connections are made we will move forward to the coding section. As the coding for the LCD is bit longer so I won’t be attaching the screenshots from the Atmel Studio.
現在,在完成所有連接之后,我們將前進至編碼部分。 由于LCD的編碼更長,因此我不會附加Atmel Studio的屏幕截圖。
.minHeight{min-height: 250px;}@media (min-width: 1025px){.minHeight{min-height: 90px;}} .minHeight{min-height: 250px;}@media (min-width: 1025px){.minHeight{min-height: 90px;}}用C代碼在LCD上打印HELLO WORLD (C code to print HELLO WORLD on the LCD)
#include <avr/io.h> #define F_CPU 1000000 #include <util/delay.h> #define RS0 #define EN1void lcd_comm (char); void lcd_data(char); void lcd_init (void);int main(void) {lcd_init();lcd_data('H');lcd_data('E');lcd_data('L');lcd_data('L');lcd_data('O');lcd_comm(20);lcd_data('W');lcd_data('O');lcd_data('R');lcd_data('L');lcd_data('D');while(1){} }void lcd_comm(char x){PORTD = x;PORTC &= ~(1<<RS);PORTC |= 1<<EN;_delay_ms(5);PORTC &= ~(1<<EN); }void lcd_data(char x){PORTD = x;PORTC |= 1<<RS;PORTC |= 1<<EN;_delay_ms(5);PORTC &= ~(1<<EN); }void lcd_init(void){DDRD = 0xFF;DDRC = 0x03;lcd_comm(0x38);lcd_comm(0x06);lcd_comm(0x0E);lcd_comm(0x01);lcd_comm(0x80); }Explanation
說明
Firstly we have included all the header file that is required basically
首先,我們包含了所有基本需要的頭文件
At the initial condition, we have defined EN=0 and RS=1.
在初始條件下,我們已定義EN = 0和RS = 1 。
Next we have defined certain functions lcd_comm(char), lcd_data(char) and lcd_init(void).
接下來,我們定義了某些函數lcd_comm(char) , lcd_data(char)和lcd_init(void) 。
Inside the int main(void) we have written the alphabets that need to be print in the screen.
在int main(void)內部,我們編寫了需要在屏幕上打印的字母。
Also here lcd_comm(20); is the command given to the LCD to create space between the two words.
同樣在這里lcd_comm(20); 是給LCD的命令,用于在兩個單詞之間創建空格。
Inside the void lcd_comm(char x) we have taken the variable as char x, which we have assigned to PORTC.
在void lcd_comm(char x)內部,我們將變量指定為char x ,并將其分配給PORTC 。
In the next step we have masked the initial value of RS which was initially 1, and here we have made it 0.
在下一步中,我們屏蔽了RS的初始值為1的初始值,在這里將其設為0。
Next, we have made our Enable Pin high and then low by giving the time delay of 5ms in between.
接下來,通過在5ms之間設置時間延遲,將使能引腳設為高電平,然后設為低電平。
Again for the next function, we would be giving the data to LCD through this.
再次為下一個功能,我們將通過此將數據提供給LCD。
We have taken a variable x, and assigned to PORTD, again made RS pin 0 and also have done similarly the Enable pin high and then low by providing the time delay of 5ms.
我們取了一個變量x ,并將其分配給PORTD ,再次將RS引腳設置為0,并通過提供5ms的時間延遲, 將使能引腳先設置為高電平,然后設置為低電平。
In this function lcd_init(void) we have written all the commands that are required for the LCD at the beginning.
在此函數lcd_init(void)中,我們在一開始就編寫了LCD所需的所有命令。
For more detail of every command, you can check the last article that I have written about the LCD.
有關每個命令的更多詳細信息,可以查看我寫的有關LCD的最后一篇文章。
Also, the DDRD=0xFF indicates all the data pins connected to the PORTD, and DDRC=0x03 is for the connection of the ENABLE Pin and R/S pin we connected to PORTC.
同樣, DDRD = 0xFF表示連接到PORTD的所有數據引腳,而DDRC = 0x03用于連接我們連接到PORTC的ENABLE引腳和R / S引腳。
Build the program and after this debug the Hex file in the simulation software design that we have created earlier and click on the RUN button and your HELLO WORLD will appear in the Screen.
生成程序,然后在調試之后,使用我們先前創建的仿真軟件設計中的Hex文件,然后單擊RUN按鈕,您的HELLO WORLD將出現在屏幕中。
翻譯自: https://www.includehelp.com/embedded-system/print-hello-world-on-the-16x2-lcd.aspx
avr uart打印
創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎總結
以上是生活随笔為你收集整理的avr uart打印_AVR | 在16x2 LCD上打印HELLO WORLD的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: IRCTC的完整形式是什么?
- 下一篇: python 唯一元素_检查所有元素在P