共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网站征稿正在进行时,欢迎踊跃投稿啦 | |
奖!发布技术笔记,技术评测贴换取您心仪的礼品 | |
打赏了!打赏了!打赏了! |
打赏帖 | |
---|---|
vscode+cmake搭建雅特力AT32L021开发环境被打赏30分 | |
【换取逻辑分析仪】自制底板并驱动ArduinoNanoRP2040ConnectLCD扩展板被打赏47分 | |
【分享评测,赢取加热台】RISC-V GCC 内嵌汇编使用被打赏38分 | |
【换取逻辑分析仪】-基于ADI单片机MAX78000的简易MP3音乐播放器被打赏48分 | |
我想要一部加热台+树莓派PICO驱动AHT10被打赏38分 | |
【换取逻辑分析仪】-硬件SPI驱动OLED屏幕被打赏36分 | |
换逻辑分析仪+上下拉与多路选择器被打赏29分 | |
Let'sdo第3期任务合集被打赏50分 | |
换逻辑分析仪+Verilog三态门被打赏27分 | |
换逻辑分析仪+Verilog多输出门被打赏24分 |