这些小活动你都参加了吗?快来围观一下吧!>>
电子产品世界 » 论坛首页 » 综合技术 » 基础知识 » LCM1602 我的LCM1602怎么总是点不亮呢?

共2条 1/1 1 跳转至

LCM1602 我的LCM1602怎么总是点不亮呢?

院士
2006-09-17 18:14:16     打赏
LCM1602 我的LCM1602怎么总是点不亮呢?



关键词: LCM1602     我的     怎么     总是     点不     亮呢    

院士
2006-12-22 22:43:00     打赏
2楼
问 大家帮忙看一下,为什么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: 我已经调通了啊我已经调通了啊

共2条 1/1 1 跳转至

回复

匿名不能发帖!请先 [ 登陆 注册 ]