找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 2353|回复: 0
打印 上一主题 下一主题
收起左侧

avr驱动1602,不能显示,但是初始化成功了

[复制链接]
跳转到指定楼层
楼主
ID:53745 发表于 2013-9-28 17:06 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
我将之前51单片机的1602的程序移植到atm 16的avr单片机中。昨天是初始化都不行,今天慢慢的调试的已经可以正常初始化,但是就是不显示给的数据。屏幕一片亮的,就是没字符。下面我附上代码,希望帮忙看看。
#include <iom16v.h>
#include <macros.h>

#define uchar unsigned char
#define uint  unsigned int

uchar  dis1[] = "WELCOME  TO";

void delay(uchar z)
{
        uchar j;
        while(z--)
        for(j=110;j>0;j--);
       
}

void Delayms(uint ms)
{
        uint i,j;
        for(i=0;i<ms;i++)
           {
           for(j=0;j<1141;j++);
       }
       
}
//        sbit rs=P2^6;
//sbit rw=P2^5;
//        sbit en=P2^7;
//        sbit LCD=P0;


        void busy()// 测忙
{
        //P0=0xff;
        PORTC&=~BIT(6);
        PORTC|=BIT(5);

        PORTC|=BIT(7);

        while(PORTA&0X80);//判断最高位D7是否为1
        PORTC&=~BIT(7);
}

//写命令函数
        void  LCDWCom(uint com)
        {
        busy();
        PORTC&=~BIT(6);
        PORTC&=~BIT(5);                                                       
        PORTA=com;
        PORTC=BIT(7);
        Delayms(1);
        PORTC&=~BIT(7);
        }

        void  LCDWriteCom(uint com)
        {
        busy();
        PORTC&=~BIT(6);
        PORTC&=~BIT(5);                                                       
        PORTA=com;
//        P0=(com&0x0f) << 4;

        PORTC|=BIT(7);
        Delayms(1);
        PORTC&=~BIT(7);
        PORTA=(com&0x0f) << 4;
//P0=com;
       
        PORTC|=BIT(7);
        Delayms(1);
        PORTC&=~BIT(7);

        }

//写数据

        void LCDWriteByte(uint dat)
        {
                busy();
                PORTC|=BIT(6);
                PORTC&=~BIT(5);                                                       
                PORTA=dat;
                  
                PORTC|=BIT(7);
                Delayms(1);
                PORTC&=~BIT(7);
                PORTA=(dat&0x0f)<<4;
               
                PORTC|=BIT(7);
                Delayms(1);
                PORTC&=~BIT(7);       
        }
//初始化

        void LCDInit()
        {
               
//                LCDWriteCom(0x);
                 LCDWCom(0x28);
                 LCDWriteCom(0x28);
                LCDWriteCom(0x0c);
       
                LCDWriteCom(0x06);
               
                LCDWriteCom(0x01);
               
//                LCDWriteCom(0x80);
}
void main()
{
            uchar i;
          DDRA=0xff;
        DDRC|=BIT(5)|BIT(6)|BIT(7);
       
        busy();
        LCDInit();

        LCDWriteCom(0x80);                                        //Y是行
        for(i=0;dis1[i]!='\0';i++)
        {
                LCDWriteByte(dis1[i]);                     
                Delayms(10);                                                            //实现字体渐出的效果
        }       
                while(1);
}

分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享淘帖 顶 踩
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

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