找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 2912|回復: 0
打印 上一主題 下一主題
收起左側(cè)

avr驅(qū)動1602,不能顯示,但是初始化成功了

[復制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
ID:53745 發(fā)表于 2013-9-28 17:06 | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
我將之前51單片機的1602的程序移植到atm 16的avr單片機中。昨天是初始化都不行,今天慢慢的調(diào)試的已經(jīng)可以正常初始化,但是就是不顯示給的數(shù)據(jù)。屏幕一片亮的,就是沒字符。下面我附上代碼,希望幫忙看看。
#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);
}

//寫命令函數(shù)
        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);

        }

//寫數(shù)據(jù)

        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);                                                            //實現(xiàn)字體漸出的效果
        }       
                while(1);
}

分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享淘帖 頂 踩
回復

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規(guī)則

手機版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術交流QQ群281945664

Powered by 單片機教程網(wǎng)

快速回復 返回頂部 返回列表