原创 C8051F020 LCD1602

2008-10-8 01:03 2475 1 1 分类: MCU/ 嵌入式

#include <c8051f020.h>                


unsigned long x;    
unsigned char xdata Netdata[16]={0x77,0x77,0x77,0x2e,0x78,0x68,0x6c,0x2e,0x63,0x6f,
                                0x6d,0x2e,0x63,0x6e};                                
                               
                            
unsigned char xdata NCDdata[17]={0x20,0x20,0x42,0x54,0x20,0x46,0x30,0x32,0x30,0x20,
                                 0x56,0x31,0x2e,0x30,0x20,0x20};
                                                             
unsigned char *lcdpoint;       
unsigned char lcd_data_count;

void SYSCLK_Init (void);
void PORT_Init (void);
void LCD_Init(void);

void main (void)
 {
 static unsigned char data1;
    WDTCN = 0xde;
    WDTCN = 0xad;                      


    SYSCLK_Init ();                
                                          
    PORT_Init ();                         


  while(1){
  LCD_Init();                       
     P2  = 0xA0;//10100000 RS="1"; 


                                    
     for(x=0;x<5000;x++);
     lcdpoint=&NCDdata;    
     for(lcd_data_count=14;lcd_data_count>0;lcd_data_count--)
     {
      data1=*lcdpoint;     
      P3 = data1;      


   P2 = 0X20;//00100000 RS="1";RW=0;E=0;
         P2 = 0XA0;//10100000 RS="1";RW=0;E=1;
                       lcdpoint++;
   for(x=0;x<5000;x++);  //delay
  }
  P2 = 0X80; //10000000  RS="0";RW=0;E=1;
     P3 = 0xc0; //11000000  RS="0";RW=1;E=1;
     P2 = 0x00; //00000000  RS="0";RW=0;E=1;  
     P2 = 0x80; //10000000  RS="0";RW=0;E=1;  
     for(x=0;x<1000;x++);
     lcdpoint=&Netdata;
     for(lcd_data_count=14;lcd_data_count>0;lcd_data_count--)
     {
      data1=*lcdpoint;
      P3 = data1; 

      P2 = 0xA0; //10100000 RS="1"; RW="0"; E="1";
                    
            P2 = 0x20; //00100000 RS="1";RW=0;E=0;

         lcdpoint++;
   for(x=0;x<5000;x++);
  }
 }
}


 


  void SYSCLK_Init (void)
{
   //int i;                              // delay counter


   //OSCXCN = 0x67;                      // start external oscillator with
                                       // 22.1184MHz crystal


   //for (i=0; i < 256; i++) ;           // Wait for osc. to start up


   //while (!(OSCXCN & 0x80)) ;          // Wait for crystal osc. to settle


   //OSCICN = 0x88;   


   OSCICN = 0x05;                                                                      
 }


 


void PORT_Init (void)
{


   XBR0     = 0x00;             
   XBR2     = 0x40;
   P2MDOUT  = 0xe0;                  
}



void LCD_Init(void)
{
   P2 = 0X80; //10000000  RS="0";RW=0;E=1;
   for(x=0;x<50000;x++);
   //P7 = 0x30;   
   P3 = 0x38;    
   P2 = 0X00;//0x08;
   P2 = 0X80;//0x09;
   for(x=0;x<1000;x++);
   P3 = 0x0e;
   P2 = 0x00;
   P2 = 0x80;
   for(x=0;x<1000;x++);
   P3=  0x06;
   P2 = 0x00;
   P2 = 0x80;
   for(x=0;x<5000;x++);
   P3 = 0x01;
   P2 = 0x00;
   P2 = 0x80;
   for(x=0;x<5000;x++);
}

广告

文章评论 0条评论)

登录后参与讨论
相关推荐阅读
412922521_325344472 2009-11-15 00:44
通用按键消抖函数 -- 数据与过程分离
AUTO:  nicksean 不务正业          项目里经常处理按键消抖, 本来这个消抖的过程是与具体按下的键无关的, 可以前的代码总是在消抖的同时处理具体的按键值, 再加上长按 短按 组合...
412922521_325344472 2009-11-13 13:16
液晶ST7920串行显示
液晶显示128*64以7920为主控制器,采用3线制,比较经济简单。代码如下.....
412922521_325344472 2009-11-13 13:11
DS18B20 C51完整版
使用WINBOND W78C516单片机,11.0592MHZ晶振,用共阳LED数码管P0口输出段码,P1口扫描/*******************************************...
412922521_325344472 2009-11-12 13:19
74HC164驱动数码管
          74HC164是串行输入,并行输出接口器件,可用在单向的并行输出/并行地址锁存等. 74HC164因为价格便宜,容易使用特别适合使用在在需要用到数码管显示IO口又比较紧张的电子产品...
412922521_325344472 2009-11-10 20:13
at24c512多字节读写函数 欢迎测试
刚写的at24c512多字节读写函数,欢迎测试。/********************************************************************函数功能:EE...
412922521_325344472 2009-11-10 19:59
旋转编码器
    很好的旋转编码器的读码程序,设旋转编码器的输出波形如下                 ______        ______        ______        ______正转时:...
广告
我要评论
0
1
广告
关闭 热点推荐上一条 /3 下一条