共2条
1/1 1 跳转至页
LCM1602 我的LCM1602怎么总是点不亮呢?
问
大家帮忙看一下,为什么LCM1602点不亮呢?好几天了啊。
/**************************************************
*|LCM---1602----------------AT91SAM7S64-----|
*-------------------------------------------|
*|DB0-----PA13 | DB4-----PA17 | RS-------PA3|
*|DB1-----PA14 | DB5-----PA18 | R/W------PA2|
*|DB2-----PA15 | DB6-----PA19 | E--------PA1|
*|DB3-----PA16 | DB7-----PA20 | VDD-----接5V|
*****************************************************/
#include <at91sam7s64.h>
#define uchar unsigned char
#define uint unsigned int
#define ulong unsigned long int
#define LCD_RS 3
#define LCD_RW 2
#define LCD_EN 1
void delay_nus(unsigned int n) ;
void delay_nms(unsigned int n) ;
void LCD_init (void);
void LCD_write_char (uint command,uchar data);
void delay_1us(void) //1us延时函数
{
;
}
void delay_nus(unsigned int n) //N us延时函数
{
unsigned int i=0;
for (i=0;i<n;i++)
delay_1us();
}
void delay_1ms(void) //1ms延时函数
{
unsigned int i;
for (i=0;i<1140;i++);
}
void delay_nms(unsigned int n) //N ms延时函数
{
unsigned int i=0;
for (i=0;i<n;i++)
delay_1ms();
}
void io_set(uint pin) //单个IO口置位函数
{
uint io_data=1;
io_data=io_data<<pin;
*AT91C_PIOA_SODR=io_data; //PIO_ODSR为IO线上置位寄存器,1有效,0无
}
void io_clear(uint pin) //单个IO口清零函数
{
ulong io_data=1;
io_data=io_data<<pin;
*AT91C_PIOA_CODR=io_data; //PIO_CODR为IO线上清零寄存器,1有效,0无
}
void LCD_init(void) //液晶初始化
{
uint i;
delay_nms(1000);
for(i=0;i<5;i++)
{
LCD_write_char(1,0x38); //8位显示,5*7点阵字符
delay_nms(40);
}
LCD_write_char(1,0x06); //8位显示,5*7点阵字符
delay_nms(40);
LCD_write_char(1,0x01); //清屏
delay_nms(40);
LCD_write_char(1,0x0f); //显示开,光标开,闪烁开
delay_nms(40);
}
void LCD_write_char(uint command,uchar data) // 写数据或者命令
{
uint i;
for(i=0;i<8;i++)
{
if(data&1) {io_set(i+13);} //根据数据或地址把相应的IO口置位或者清零,低位在先,高位在后
else {io_clear(i+13);}
data=data>>1;
}
if(command==0) io_set(LCD_RS); //写数据RS=1
else io_clear(LCD_RS); //写地址RS=0
io_clear(LCD_RW); //R/W=0
io_clear(LCD_EN); //EN=0
delay_nus(200);
io_set(LCD_EN); //EN=1
delay_nus(100);
io_clear(LCD_EN); //EN=0
}
void LCD_set_xy( unsigned char x, unsigned char y ) //写地址函数
{
unsigned char address;
if (y == 0) address = 0x80 + x;
else
address = 0xc0 + x;
LCD_write_char(1,address);
}
void main(void)
{
*AT91C_PMC_PCER=0x0F; //PMC外设时钟使能
*AT91C_PIOA_PER=0xffffffff; //PIOA0-31作为I/O使用
*AT91C_PIOA_OER=0xffffffff; //I/O输出使能
delay_nus(10);
LCD_init(); //1602初始化
while(1)
{
LCD_set_xy(0,0);
LCD_write_char(0,'w');
LCD_write_char(0,'w');
LCD_write_char(0,'w');
LCD_write_char(0,'.');
LCD_write_char(0,'2');
LCD_write_char(0,'1');
LCD_write_char(0,'i');
LCD_write_char(0,'c');
LCD_write_char(0,'.');
LCD_write_char(0,'c');
LCD_write_char(0,'o');
LCD_write_char(0,'m');
delay_nms(1000);
LCD_set_xy(4,1);
LCD_write_char(0,'a');
LCD_write_char(0,'t');
LCD_write_char(0,'9');
LCD_write_char(0,'1');
LCD_write_char(0,'s');
LCD_write_char(0,'a');
LCD_write_char(0,'m');
LCD_write_char(0,'7');
LCD_write_char(0,'s');
LCD_write_char(0,'6');
LCD_write_char(0,'4');
delay_nms(1000);
}
} 答 1: 我已经调通了啊我已经调通了啊
/**************************************************
*|LCM---1602----------------AT91SAM7S64-----|
*-------------------------------------------|
*|DB0-----PA13 | DB4-----PA17 | RS-------PA3|
*|DB1-----PA14 | DB5-----PA18 | R/W------PA2|
*|DB2-----PA15 | DB6-----PA19 | E--------PA1|
*|DB3-----PA16 | DB7-----PA20 | VDD-----接5V|
*****************************************************/
#include <at91sam7s64.h>
#define uchar unsigned char
#define uint unsigned int
#define ulong unsigned long int
#define LCD_RS 3
#define LCD_RW 2
#define LCD_EN 1
void delay_nus(unsigned int n) ;
void delay_nms(unsigned int n) ;
void LCD_init (void);
void LCD_write_char (uint command,uchar data);
void delay_1us(void) //1us延时函数
{
;
}
void delay_nus(unsigned int n) //N us延时函数
{
unsigned int i=0;
for (i=0;i<n;i++)
delay_1us();
}
void delay_1ms(void) //1ms延时函数
{
unsigned int i;
for (i=0;i<1140;i++);
}
void delay_nms(unsigned int n) //N ms延时函数
{
unsigned int i=0;
for (i=0;i<n;i++)
delay_1ms();
}
void io_set(uint pin) //单个IO口置位函数
{
uint io_data=1;
io_data=io_data<<pin;
*AT91C_PIOA_SODR=io_data; //PIO_ODSR为IO线上置位寄存器,1有效,0无
}
void io_clear(uint pin) //单个IO口清零函数
{
ulong io_data=1;
io_data=io_data<<pin;
*AT91C_PIOA_CODR=io_data; //PIO_CODR为IO线上清零寄存器,1有效,0无
}
void LCD_init(void) //液晶初始化
{
uint i;
delay_nms(1000);
for(i=0;i<5;i++)
{
LCD_write_char(1,0x38); //8位显示,5*7点阵字符
delay_nms(40);
}
LCD_write_char(1,0x06); //8位显示,5*7点阵字符
delay_nms(40);
LCD_write_char(1,0x01); //清屏
delay_nms(40);
LCD_write_char(1,0x0f); //显示开,光标开,闪烁开
delay_nms(40);
}
void LCD_write_char(uint command,uchar data) // 写数据或者命令
{
uint i;
for(i=0;i<8;i++)
{
if(data&1) {io_set(i+13);} //根据数据或地址把相应的IO口置位或者清零,低位在先,高位在后
else {io_clear(i+13);}
data=data>>1;
}
if(command==0) io_set(LCD_RS); //写数据RS=1
else io_clear(LCD_RS); //写地址RS=0
io_clear(LCD_RW); //R/W=0
io_clear(LCD_EN); //EN=0
delay_nus(200);
io_set(LCD_EN); //EN=1
delay_nus(100);
io_clear(LCD_EN); //EN=0
}
void LCD_set_xy( unsigned char x, unsigned char y ) //写地址函数
{
unsigned char address;
if (y == 0) address = 0x80 + x;
else
address = 0xc0 + x;
LCD_write_char(1,address);
}
void main(void)
{
*AT91C_PMC_PCER=0x0F; //PMC外设时钟使能
*AT91C_PIOA_PER=0xffffffff; //PIOA0-31作为I/O使用
*AT91C_PIOA_OER=0xffffffff; //I/O输出使能
delay_nus(10);
LCD_init(); //1602初始化
while(1)
{
LCD_set_xy(0,0);
LCD_write_char(0,'w');
LCD_write_char(0,'w');
LCD_write_char(0,'w');
LCD_write_char(0,'.');
LCD_write_char(0,'2');
LCD_write_char(0,'1');
LCD_write_char(0,'i');
LCD_write_char(0,'c');
LCD_write_char(0,'.');
LCD_write_char(0,'c');
LCD_write_char(0,'o');
LCD_write_char(0,'m');
delay_nms(1000);
LCD_set_xy(4,1);
LCD_write_char(0,'a');
LCD_write_char(0,'t');
LCD_write_char(0,'9');
LCD_write_char(0,'1');
LCD_write_char(0,'s');
LCD_write_char(0,'a');
LCD_write_char(0,'m');
LCD_write_char(0,'7');
LCD_write_char(0,'s');
LCD_write_char(0,'6');
LCD_write_char(0,'4');
delay_nms(1000);
}
} 答 1: 我已经调通了啊我已经调通了啊
共2条
1/1 1 跳转至页
回复
我要赚赏金打赏帖 |
|
|---|---|
| 28BYJ-48机械臂实现人脸跟随被打赏¥24元 | |
| 基于RK3506B的片温识读功能的实现被打赏¥25元 | |
| 【瑞萨RA8D1测评】基于FreeRTOS的lvgl移植教程被打赏¥29元 | |
| 电子价签墨水屏开发被打赏¥35元 | |
| 【Ozone】RTT 打印终端使用被打赏¥29元 | |
| BMS保护板绝缘检测功能-不平衡电桥技术绝缘电阻检测设计与实现被打赏¥34元 | |
| 给28BYJ-48三自由度机械臂加一个网页控制台被打赏¥32元 | |
| 用28BYJ-48电机从零搭一台三自由度机械臂被打赏¥33元 | |
| 【英飞凌开发经验】ModusToolbox配置EdgeTalk外设被打赏¥27元 | |
| 基于BQ76952PFBR的BMS保护板热插拔损坏的原因和处理措施被打赏¥32元 | |
我要赚赏金
