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

模拟

Simulation, AVR | Print HELLO WORLD on the 16x2 LCD

Explanation

说明

  • Search these devices from the device selection menu:

    从设备选择菜单中搜索以下设备:

    1. ATmega16
    2. LM016L (It’s a 16*2 Alphanumeric LCD)
    3. One Power Terminal
    4. 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的屏幕截图。

用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 EN1

void 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打印

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
电赛Altium Designer原件大全,原理图+PCB封装 AD603, AD603_2, AD8009, AD831, AD8314, AD8361, AD8367, ADF4351, ADL5536, ADS1293, ADS1293_Module, ADXL345, AH101, AMS1117, AT24C1024, Battery, Beep, BNC, Cap, Cap_Pol, CC2541-MOD, CH340G, Diode, Diode_Z, GND, Header 10, Header 10H, Header 10X2, Header 10X2A, Header 10X2H, Header 11, Header 11H, Header 11X2, Header 11X2A, Header 11X2H, Header 12, Header 12H, Header 12X2, Header 12X2A, Header 12X2H, Header 13, Header 13H, Header 13X2, Header 13X2A, Header 13X2H, Header 14, Header 14H, Header 14X2, Header 14X2A, Header 14X2H, Header 15, Header 15H, Header 15X2, Header 15X2A, Header 15X2H, Header 16, Header 16H, Header 16X2, Header 16X2A, Header 16X2H, Header 17, Header 17H, Header 17X2, Header 17X2A, Header 17X2H, Header 18, Header 18H, Header 18X2, Header 18X2H, Header 19, Header 19H, Header 19X2, Header 19X2H, Header 2, Header 20, Header 20H, Header 20X2, Header 20X2H, Header 22, Header 22H, Header 22X2, Header 22X2H, Header 24, Header 24H, Header 24X2, Header 24X2H, Header 25, Header 25H, Header 25X2, Header 25X2H, Header 2H, Header 2X2, Header 2X2H, Header 3, Header 30, Header 30X2, Header 3H, Header 3X2, Header 3X2A, Header 3X2H, Header 4, Header 4H, Header 4X2, Header 4X2A, Header 4X2H, Header 5, Header 5H, Header 5X2, Header 5X2A, Header 5X2H, Header 6, Header 6H, Header 6X2, Header 6X2A, Header 6X2H, Header 7, Header 7H, Header 7X2, Header 7X2A, Header 7X2H, Header 8, Header 8H, Header 8X2, Header 8X2A, Header 8X2H, Header 9, Header 9H, Header 9X2, Header 9X2A, Header 9X2H, HeadphoneSocket, HMC470, HMC472A, INA333, Ind, JTAG, LED, LM317, LM358, MB506, MC34063, MHDR1X10, MHDR1X11, MHDR1X12, MHDR1X13, MHDR1X14, MHDR1X15, MHDR1X16, MHDR1X17, MHDR1X18, MHDR1X19, MHDR1X2, MHDR1X20, MHDR1X3, MHDR1X4, MHDR1X5, MHDR1X6, MHDR1X7, MHDR1X8, MHDR1X9, MHDR2X10, MHDR2X11, MHDR2X12, MHDR2X13, MHDR2X14, MHDR2X15, MHDR2X16, MHDR2X17, MHDR2X18, MHDR2X19, MHDR2X2, MHDR2X20, MHDR2X3, MHDR2X4, MHDR2X5, MHDR2X6, MHDR2X7, MHDR2X8, MHDR2X9, MIC5219-3.3, MPU6050, MPU6050_module, NE5532, NPN, NPN_SOT23, nrf58122, OPA2333, OPA695, OPA847, PE4302, PNP, PNP_SOT23, PW2, PW3, PW4, Res, Res_8P4R, Res_pot, SMA, STC12C5A60S2, STC15F2K60S2, STM32F103RDT6, SW, SW_BTN, SW_DIP_4, SW_DIP_5, SW_DIP_6, SW_DIP_8, SW_PB, SX1308, Test, Test_6, THS3201, tlv3501, TP4056, TP5400, USB, USB_M, VCA810, VCA821, XC6206, XL6009, XTAL, XTAL_SMD
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值