共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 跳转至页
回复
有奖活动 | |
---|---|
【EEPW电子工程师创研计划】技术变现通道已开启~ | |
发原创文章 【每月瓜分千元赏金 凭实力攒钱买好礼~】 | |
【EEPW在线】E起听工程师的声音! | |
“我踩过的那些坑”主题活动——第001期 | |
高校联络员开始招募啦!有惊喜!! | |
【工程师专属福利】每天30秒,积分轻松拿!EEPW宠粉打卡计划启动! | |
送您一块开发板,2025年“我要开发板活动”又开始了! | |
打赏了!打赏了!打赏了! |
打赏帖 | |
---|---|
【我踩过的那些坑】结构堵孔导致的喇叭无声问题被打赏50分 | |
【我踩过的那些坑】分享一下调试一款AD芯片的遇到的“坑”被打赏50分 | |
电流检测模块MAX4080S被打赏10分 | |
【我踩过的那些坑】calloc和malloc错误使用导致跑飞问题排查被打赏50分 | |
多组DCTODC电源方案被打赏50分 | |
【我踩过的那些坑】STM32cubeMX软件的使用过程中的“坑”被打赏50分 | |
新手必看!C语言精华知识:表驱动法被打赏50分 | |
【我踩过的那些坑】杜绑线问题被打赏50分 | |
【我踩过的那些坑】STM32的硬件通讯调试过程的“坑”被打赏50分 | |
【我踩过的那些坑】晶振使用的问题被打赏100分 |