找回密码
 立即注册

QQ登录

只需一步,快速开始

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

求教大侠们,我的工程为什么实现不了相应的功能?具体看附件,谢谢!

[复制链接]
跳转到指定楼层
楼主
ID:282384 发表于 2018-3-23 08:29 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
我已经研究的一个星期了,没辙了,所以求助于各位大虾了,谢谢了!

#include"lcd12864.h"


void LCD_busy()       
{
   bit busy;
   LCD_E = 0;
   LCD_RS = 0;
   LCD_RW = 1;  
   do{
          LCD_Busy = 1;
          LCD_E = 1;
                _nop_();
          busy = LCD_Busy;
          LCD_E = 0;
          }while(busy);
}
void LCD_WriteCode(unsigned char cmd)
{
   LCD_busy();
   LCD_E = 0;
   LCD_RS = 0;
   LCD_RW = 0;
   LCD_Data = cmd;
   LCD_E = 1;
         _nop_();
   LCD_E = 0;       
}
void LCD_GoToXY(unsigned char x,unsigned char y)
{
        y = y%4;//y取值为0、1、2、3
        x = x%8;//x取值为0~7
        switch(y){
                case 0:
                        x |= 0x80;
                        break;
                case 1:
                        x |= 0x90;
                        break;
                case 2:
                        x |= 0x88;
                        break;
                case 3:
                        x |= 0x98;
                        break;
        }
        LCD_WriteCode(x);
}
void LCD_WriteData(unsigned char dat)
{
   LCD_busy();
   LCD_RS = 1;          
   LCD_RW = 0;
   LCD_Data = dat;
   LCD_E = 1;
         _nop_();
   LCD_E = 0;
}
void LCD_Init()
{
   LCD_RST = 1;
         LCD_PSB = 1;//并口通讯
         LCD_E = 0;
   LCD_WriteCode(0x08);//关显示 ,关光标显示  
   LCD_Clear();//清屏
   LCD_WriteCode(0x30);//显示模式设定为基本功能模式
   LCD_WriteCode(0x06);//读或写一个字符后,地址加1,整屏不移动  
   LCD_WriteCode(0x0c);//开显示
         LCD_BG = 0;//开启背光

}
void LCD_Clear()
{
   LCD_WriteCode(0x01);
}
void LCD_ShowString(unsigned char x,unsigned char y,unsigned char *str){
        LCD_GoToXY(x,y);
        while(*str){
                LCD_WriteData(*str);
                str++;
                delay1(3000);
        }
}

void LCD_ShowImg(unsigned char dat[]){//显示自定义图形
        unsigned char i,j;
        for(i=0; i<32; i++){//写上半部分屏
                LCD_WriteCode(0x34);//打开扩展功能模式
                LCD_WriteCode(0x80|i);//行地址
                LCD_WriteCode(0x80);//列地址
                LCD_WriteCode(0x30);//关闭扩展功能,回到基本功能模式
                for(j=0; j<16; j++){//写入图像数据
                        LCD_WriteData(*dat);
                        dat++;
                }
        }
        for(i=0; i<32; i++){//写下半部分屏
                LCD_WriteCode(0x34);//打开扩展功能模式
                LCD_WriteCode(0x80|i);//行地址
                LCD_WriteCode(0x88);//列地址
                LCD_WriteCode(0x30);//关闭扩展功能,回到基本功能模式
                for(j=0; j<16; j++){//写入图像数据
                        LCD_WriteData(*dat);
                        dat++;
                }
        }
        //LCD_WriteCode(0x36);//打开扩展功能,开启显示
        //LCD_WriteCode(0x30);//关闭扩展功能,回到基本功能模式
}

void LCD_Flash(){//显示内容闪烁
        unsigned char i;
        for(i=0; i<3; i++){
                delay1(40000);
                LCD_WriteCode(0x08);//显示关
                delay1(30000);
                LCD_WriteCode(0x0C);//显示开
        }
}

void delay1(unsigned int n){
        for(; n>0; n--);
}

   LCD文件;

/*  名称:播放音乐
说明:程序运行时播放生日快乐歌, 未使用定时器中断,所有频率完全用延时实现
*/

#include"lcd12864.h"
#define uchar unsigned char
#define uint unsigned int

sfr  P4  = 0xE8;//??P4????
sbit P4_4 = P4^4;//??P4.4????

sbit BEEP=P4^4;
//生日快乐歌的音符频率表,不同频率由不同的延时来决定
uchar code SONG_TONE[]={212,212,190,212,159,169,212,212,190,212,142,159,
212,212,106,126,159,169,190,119,119,126,159,142,159,0};
//生日快乐歌节拍表,节拍决定每个音符的演奏长短
uchar code SONG_LONG[]={9,3,12,12,12,24,9,3,12,12,12,24,
9,3,12,12,12,12,12,9,3,12,12,12,24,0};
//延时

code unsigned char IMG[]={//128*64??????
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X70,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X70,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X60,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X03,0X00,0X00,0X00,0X04,0X00,
0X00,0X00,0X40,0X00,0X00,0X00,0X00,0X00,0X00,0X06,0X03,0X00,0X00,0X00,0X1C,0X00,
0X00,0X00,0X80,0X00,0X00,0X00,0X00,0XC0,0X00,0X1E,0X03,0X00,0X00,0X00,0X1C,0X00,
0X00,0X01,0X7E,0X00,0X00,0X1E,0X01,0XC0,0X00,0X3E,0X03,0X00,0X00,0X10,0X18,0X00,
0X00,0X03,0XFF,0X00,0X00,0X7E,0X01,0XC0,0X00,0X60,0X03,0X00,0X00,0X10,0X18,0X00,
0X00,0X07,0X07,0X00,0X00,0X7E,0X01,0X80,0X00,0X80,0X03,0X00,0X00,0X10,0X1F,0X00,
0X00,0X0C,0X06,0X00,0X00,0XEC,0X03,0X80,0X01,0X00,0X03,0X00,0X00,0X10,0X3F,0X00,
0X00,0X18,0X0C,0X00,0X00,0X18,0X07,0XB8,0X00,0X00,0X73,0X00,0X00,0X3C,0X7E,0X00,
0X00,0X03,0X18,0X00,0X00,0X20,0X3F,0XFC,0X00,0X18,0XF3,0X00,0X01,0XF8,0XFC,0X00,
0X00,0X07,0X78,0X00,0X00,0X04,0X7F,0XBC,0X00,0X3C,0X43,0X00,0X03,0XF0,0X78,0X00,
0X00,0X07,0XF8,0X00,0X00,0X3E,0X7F,0X1C,0X08,0X38,0X43,0X00,0X03,0X90,0X18,0X00,
0X00,0X0D,0XF0,0X00,0X00,0XFE,0X0E,0X18,0X08,0XF8,0X71,0X00,0X00,0X10,0X10,0X00,
0X00,0X08,0XC0,0X00,0X07,0XFC,0X0C,0X18,0X09,0XF0,0XF1,0X00,0X00,0X10,0X32,0X00,
0X00,0X18,0X00,0X00,0X0F,0XF8,0X1C,0X18,0X1F,0XF0,0X61,0X00,0X00,0X18,0X7F,0X00,
0X00,0X10,0X00,0X00,0X0F,0X72,0X18,0X18,0X1F,0XE0,0X61,0XF0,0X01,0X18,0XFF,0X00,
0X00,0X20,0X3F,0X00,0X00,0XE7,0X38,0X10,0X1F,0XD8,0XC7,0XE0,0X01,0X11,0XF3,0X00,
0X00,0X20,0XFF,0X80,0X00,0XCF,0X30,0X20,0X09,0XF9,0X3F,0X80,0X02,0X11,0X83,0X00,
0X00,0X4F,0XFF,0X80,0X03,0X9E,0X61,0XC0,0X03,0XF3,0XFF,0X80,0X06,0X13,0X86,0X00,
0X00,0X9B,0XF3,0X80,0X07,0XF0,0X63,0XC0,0X03,0XC7,0XF3,0X80,0X0C,0X13,0XEC,0X00,
0X01,0X9A,0X03,0X00,0X07,0XE0,0XC3,0X00,0X06,0XC7,0X83,0X80,0X0C,0X11,0XFC,0X00,
0X03,0X0C,0X06,0X00,0X07,0X01,0X80,0X00,0X04,0XC0,0X03,0X00,0X1C,0X20,0XFF,0XF0,
0X06,0X0E,0X7E,0X00,0X00,0X01,0X00,0X00,0X08,0X40,0X03,0X00,0X03,0X21,0XDF,0XFC,
0X0C,0X06,0XFE,0X00,0X00,0X03,0X00,0X00,0X00,0X40,0X03,0X00,0X03,0XDE,0X00,0X70,
0X08,0X02,0X7C,0X00,0X00,0X06,0X00,0X00,0X00,0X00,0X02,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X08,0X00,0X00,0X00,0X00,0X02,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X02,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X10,0X24,0X00,0X12,0X01,0X00,0X00,0X02,0X0E,0X1C,0X38,0X70,0X23,0XE3,0X8F,0X80,
0X10,0X24,0X00,0X12,0X01,0X00,0X00,0X06,0X11,0X22,0X44,0X88,0X60,0X44,0X41,0X00,
0X16,0X7E,0XB1,0X24,0X71,0X61,0XC5,0X8A,0X11,0X20,0X40,0X08,0X60,0X40,0X41,0X00,
0X19,0X24,0XC8,0X24,0X89,0X92,0X26,0X42,0X11,0X2C,0X58,0X08,0XA0,0X80,0X42,0X00,
0X11,0X24,0X88,0X24,0X81,0X12,0X24,0X42,0X11,0X32,0X64,0X10,0XA0,0X81,0X82,0X00,
0X11,0X24,0X88,0X24,0X71,0X12,0X24,0X42,0X11,0X22,0X44,0X11,0X20,0X80,0X42,0X00,
0X11,0X24,0X88,0X24,0X09,0X12,0X24,0X42,0X11,0X22,0X44,0X21,0XF1,0X00,0X44,0X00,
0X11,0X24,0XC8,0X48,0X89,0X12,0X26,0X42,0X11,0X22,0X44,0X40,0X21,0X04,0X44,0X00,
0X11,0X36,0XB1,0X48,0X71,0X11,0XC5,0X82,0X0E,0X1C,0X38,0XF8,0X21,0X03,0X84,0X00,
0X00,0X00,0X80,0X00,0X00,0X00,0X04,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X80,0X00,0X00,0X00,0X04,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X10,0X00,0X08,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X10,0X00,0X08,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X39,0XC3,0X8B,0X0E,0X1C,0X06,0X1C,0X59,0X80,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X12,0X24,0X4C,0X91,0X22,0X09,0X22,0X66,0X40,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X10,0X24,0X48,0X81,0X22,0X08,0X22,0X44,0X40,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X11,0XE4,0X48,0X8F,0X22,0X08,0X22,0X44,0X40,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X12,0X24,0X48,0X91,0X22,0X08,0X22,0X44,0X40,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X12,0X64,0X4C,0X93,0X22,0X09,0X22,0X44,0X40,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X99,0XA3,0X8B,0X0D,0X1C,0X46,0X1C,0X44,0X40,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
};



code unsigned char top[] = "^_^ 家电维修 ^_^ ";
        code unsigned char li0[] = "    二手回收";
        code unsigned char li1[] = "    专业服务";
        code unsigned char bottom[] = "TEL:404058326";


void DelayMS(uint x)
{
uchar t;
while(x--) for(t=0;t<120;t++);
}


//播放函数
void PlayMusic()
{


uint i=0,j,k;

while(SONG_LONG[i]!=0||SONG_TONE[i]!=0)
{ //播放各个音符,SONG_LONG 为拍子长度
for(j=0;j<SONG_LONG[i]*20;j++)
{
BEEP=~BEEP;
//SONG_TONE 延时表决定了每个音符的频率
for(k=0;k<SONG_TONE[i]/3;k++);
}
DelayMS(10);
i++;
       }
}

void timer0()
{

  TMOD=0X01;
        TH0=0XB8;
        TL0=0X00;
        TR0=1;
       
}
void t0() interrupt 1

{

  EA=1;
  ET0=1;//IE=0x82 //CPU???,CT0???

LCD_Init();

        while(1)
        {
                LCD_Clear();
                LCD_ShowImg(IMG);
                delay1(65535);
                LCD_Flash();
                LCD_Clear();
                LCD_ShowString(0,0,top);
                delay1(10000);
                LCD_ShowString(0,1,li0);
                delay1(10000);
                LCD_ShowString(0,2,li1);
                delay1(10000);
                LCD_ShowString(0,3,bottom);
                LCD_Flash();
                delay1(65535);
        }

}

void main()
{


void timer0();


BEEP=0;
while(1)
{
PlayMusic(); //播放生日快乐
DelayMS(500); //播放完后暂停一段时间

}

TMOD=0X01;
        TH0=0XB8;
        TL0=0X00;
        TR0=1;

EA=1;
  ET0=1;//IE=0x82 //CPU???,CT0???


}

   音乐文件;
目前只有音乐播放功能,LCD12864无法使用,请各位大神赐教1

m.zip

42.24 KB, 下载次数: 4

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

使用道具 举报

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

本版积分规则

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

Powered by 单片机教程网

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