搜索
bottom↓
回复: 0

C8051F410编写程序但是1602显示不出来,哪里错了,怎么改?

[复制链接]

出0入0汤圆

发表于 2012-7-6 15:06:31 | 显示全部楼层 |阅读模式
代码如下:
#include  <C8051F410.h>
#include  <math.h>    //Keil library  
#include  <stdio.h>   //Keil library       
#include  <INTRINS.H>
#define   uchar unsigned char
#define   uint unsigned int       
unsigned char xdata Netdata[14]={0x77,0x77,0x77,0x2e,0x78,0x68,0x6c,0x2e
                                 ,0x63,0x6f,0x6d,0x2e,0x63,0x6e};
unsigned char xdata NCDdata[14]={0x57,0x65,0x6c,0x63,0x6f,0x6d,0x65,0x20
                                 ,0x74,0x6f,0x20,0x4e,0x43,0x44};

sbit LCM_EN=P1^0;
sbit LCM_RW=P1^1;
sbit LCM_RS=P1^2;
#define   DataPort P0

void delay(int i)
{
     int j,k;
     for(j=0;j<i;j++)
     for(k=0;k<1000;k++);
}

void WaitForEnable(void)       
{                                       
DataPort=0xff;               
LCM_RS=0;
LCM_RW=1;
_nop_();
LCM_EN=1;
_nop_();
_nop_();
while(DataPort&0x80);       
LCM_EN=0;                               
}

void WriteCommandLCM(uchar CMD,uchar Attribc)
{
if(Attribc)WaitForEnable();                                               
LCM_RS=0;LCM_RW=0;
_nop_();
DataPort=CMD;
_nop_();       
LCM_EN=1;
_nop_();
_nop_();
LCM_EN=0;
}

void WriteDataLCM(uchar dataW)
{                                       
WaitForEnable();       
LCM_RS=1;LCM_RW=0;
_nop_();
DataPort=dataW;
_nop_();       
LCM_EN=1;
_nop_();
_nop_();
LCM_EN=0;
}

void InitLcd()                               
{                       
WriteCommandLCM(0x38,1);       
WriteCommandLCM(0x08,1);       
WriteCommandLCM(0x01,1);       
WriteCommandLCM(0x06,1);       
WriteCommandLCM(0x0c,1);
}       

void SYSCLK_Init(void)
{
        OSCICN    = 0x87;
}

void PORT_Init(void)
{
    P0MDOUT   = 0xFF;
    P1MDOUT   = 0xFF;
    XBR1      = 0x40;
}

void main()
{
   unsigned int i;
    PCA0MD    &= ~0x40;

        SYSCLK_Init();
        PORT_Init();
        InitLcd();
        //write_com(0x80);
        //write_data('H');          

        while(1)  //最后程序停留在while语句中
        {
                   for(i=0;i<14;i++)
            {
                    WriteDataLCM(Netdata[i]);
                     delay(20);
            }
            WriteCommandLCM(0x80+0x51,1);
            for(i=0;i<14;i++)
            {
                    WriteDataLCM(NCDdata[i]);
                    delay(20);
            }       
            for(i=0;i<14;i++)           //整屏左移
            {
                    WriteCommandLCM(0x18,1);  //整屏左移一个字节
                    delay(400);
            }
                InitLcd();
          /*unsigned int n;
                for(n=0;n<14;n++)
                {
                write_data(NCDdata[n]);
                }
                delay(5);
                LCD_Init();*/       
        }
}

阿莫论坛20周年了!感谢大家的支持与爱护!!

曾经有一段真挚的爱情摆在我的面前,我没有珍惜,现在想起来,还好我没有珍惜……
回帖提示: 反政府言论将被立即封锁ID 在按“提交”前,请自问一下:我这样表达会给举报吗,会给自己惹麻烦吗? 另外:尽量不要使用Mark、顶等没有意义的回复。不得大量使用大字体和彩色字。【本论坛不允许直接上传手机拍摄图片,浪费大家下载带宽和论坛服务器空间,请压缩后(图片小于1兆)才上传。压缩方法可以在微信里面发给自己(不要勾选“原图),然后下载,就能得到压缩后的图片。注意:要连续压缩2次才能满足要求!!】。另外,手机版只能上传图片,要上传附件需要切换到电脑版(不需要使用电脑,手机上切换到电脑版就行,页面底部)。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|Archiver|amobbs.com 阿莫电子技术论坛 ( 粤ICP备2022115958号, 版权所有:东莞阿莫电子贸易商行 创办于2004年 (公安交互式论坛备案:44190002001997 ) )

GMT+8, 2024-8-27 00:13

© Since 2004 www.amobbs.com, 原www.ourdev.cn, 原www.ouravr.com

快速回复 返回顶部 返回列表