写一段c程序使LCD1602液晶品示(姓名+学号),按下 K1,LCD1602液晶屏第一行显示自己姓名拼音首宇母。按下k2,LCD1602液晶屏第二行显示自己的学号。按下k3,清屏。
时间: 2023-04-07 10:02:45 浏览: 93
以下是C程序:
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
void setup() {
lcd.begin(16, 2);
pinMode(6, INPUT_PULLUP);
pinMode(7, INPUT_PULLUP);
pinMode(8, INPUT_PULLUP);
}
void loop() {
if (digitalRead(6) == LOW) {
lcd.setCursor(0, 0);
lcd.print("Your Name");
}
if (digitalRead(7) == LOW) {
lcd.setCursor(0, 1);
lcd.print("Your Student ID");
}
if (digitalRead(8) == LOW) {
lcd.clear();
}
}
相关问题
写一段单片机程序使LCD1602液晶品示(姓名+学号),按下 K1,LCD1602液晶屏第一行显示自己姓名拼音首宇母。按下k2,LCD1602液晶屏第二行显示自己的学号。按下k3,清屏。
以下是单片机程序:
#include <reg52.h>
#include <intrins.h>
#define LCD1602_DB P0
sbit LCD1602_RS = P2^6;
sbit LCD1602_RW = P2^5;
sbit LCD1602_E = P2^7;
sbit K1 = P3^0;
sbit K2 = P3^1;
sbit K3 = P3^2;
void delay(unsigned int i)
{
while(i--);
}
void write_com(unsigned char com)
{
LCD1602_RS = 0;
LCD1602_RW = 0;
LCD1602_DB = com;
LCD1602_E = 1;
_nop_();
_nop_();
LCD1602_E = 0;
}
void write_data(unsigned char dat)
{
LCD1602_RS = 1;
LCD1602_RW = 0;
LCD1602_DB = dat;
LCD1602_E = 1;
_nop_();
_nop_();
LCD1602_E = 0;
}
void init_lcd1602()
{
write_com(0x38);
write_com(0x0c);
write_com(0x06);
write_com(0x01);
}
void main()
{
unsigned char name[] = "Your Name";
unsigned char number[] = "Your Number";
unsigned char i;
init_lcd1602();
while(1)
{
if(K1 == 0)
{
write_com(0x80);
for(i=0; i<9; i++)
{
write_data(name[i]);
}
}
if(K2 == 0)
{
write_com(0xc0);
for(i=0; i<11; i++)
{
write_data(number[i]);
}
}
if(K3 == 0)
{
write_com(0x01);
}
}
}
写一段程序使LCD1602液晶品示(姓名+学号),按下 K1,LCD1602液晶屏第一行显示自己姓名拼音首宇母。按下k2,LCD1602液晶屏第二行显示自己的学号。按下k3,清屏。
以下是程序:
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
void setup() {
lcd.begin(16, 2);
pinMode(6, INPUT_PULLUP);
pinMode(7, INPUT_PULLUP);
pinMode(8, INPUT_PULLUP);
}
void loop() {
if (digitalRead(6) == LOW) {
lcd.setCursor(0, 0);
lcd.print("Your Name");
}
if (digitalRead(7) == LOW) {
lcd.setCursor(0, 1);
lcd.print("Your Student ID");
}
if (digitalRead(8) == LOW) {
lcd.clear();
}
}
阅读全文