找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 4004|回复: 7
收起左侧

Proteus中加了排阻LCD1602屏幕不亮

[复制链接]
ID:438041 发表于 2018-12-2 23:34 | 显示全部楼层 |阅读模式
本帖最后由 shurmin 于 2018-12-3 21:56 编辑

#include<reg52.h>
#include<intrins.h>
#define uchar unsigned char
#define uint unsigned int
sbit K1=P3^2;
sbit K2=P3^3;
sbit beep=P3^7;
sbit rs=P2^0;
sbit rw=P2^1;
sbit ep=P2^2;
uchar i;
uchar song_Index=0,Tone_Index=0;
uchar *song_Tone,*song_Time;
uchar *discode;
uchar code dis1[]={" Yuan Yin Wo "};//the name of the first song
uchar code dis2[]={" Cong Ci Yi Hou "};//the name of the second song
uchar code dis3[]={" 203 "};//the name of the third song
uchar code dis4[]={" 203 "};
uchar code dis5[]={" 203 "};
uchar code dis[]={"K1:Down  K2:Up"};
uint code Tone_tab[]={
        62018,62401,62491,62895,63184,63441,63506,
        63773,63965,64137,64215,64360,64488,64603,
        64654,64751,64836,64876,64948,65012,65067,65535};
uchar code song1_Tone[]={
  14,14,14,14,13,12,
        12,14,13,12,12,14,13,12,
        12,11,11,11,11,12,9,9,14,13,12,
        12,14,13,12,12,11,11,12,12,16,16,
        16,16,16,14,13,12,
        12,14,13,12,12,14,13,12,
        12,16,15,15,14,12,12,12,12,11,11,12,
        12,16,16,12,11,11,12,12,16,16,15,15,
        15,14,12,12,12,12,0xff};
uchar code song1_Time[]={
        8,8,8,4,2,2,
        8,4,2,2,4,2,1,1,
        1,1,1,1,1,2,1,4,2,1,1,
        4,2,1,1,1,1,1,1,1,2,1,
        8,8,8,2,1,1,
        4,2,1,1,4,2,1,1,
        2,1,1,1,1,1,1,4,1,1,1,1,
        1,2,1,1,1,1,1,1,2,1,2,2,
        2,1,1,8,8,8,0xff};
uchar code song2_Tone[]={
        7,7,7,5,7,
        9,8,9,8,9,12,11,9,
        8,9,9,5,7,
        9,8,9,11,8,9,8,8,8,7,
        7,9,9,7,7,8,
        9,8,9,8,9,12,13,14,
        13,13,11,11,8,9,9,7,
        5,7,9,8,8,6,6,4,
        5,5,5,5,0xff};
uchar code song2_Time[]={
        8,8,8,2,2,
        2,2,2,2,2,2,2,2,
        4,4,4,2,2,
        2,2,2,2,1,1,1,1,2,2,
        2,2,4,4,2,2,
        2,2,2,2,2,2,2,2,
        2,1,1,2,2,4,2,2,
        4,2,2,2,1,1,2,2,
        4,4,4,4,0xff};
uchar code song3_Tone[]={
  7,9,8,7,9,
        5,7,6,7,8,
        4,9,8,7,9,
        8,7,7,7,7,5,9,9,
        9,9,8,7,9,
        5,7,6,7,8,
        9,11,12,9,9,8,7,
        7,7,7,7,5,6,6,7,
        7,7,0xff};
uchar code song3_Time[]={
  8,1,1,1,1,
        8,1,1,1,1,
        8,1,1,1,1,
        1,1,1,1,1,1,1,1,
        8,1,1,1,1,
        8,1,1,1,1,
        1,1,1,1,1,1,4,
        1,1,1,1,1,1,1,1,
        8,8,0xff};
uchar code song4_Tone[]={
  14,14,14,14,13,12,
        12,14,13,12,12,14,13,12,
        12,11,11,11,11,12,9,9,14,13,12,
        12,14,13,12,12,11,11,12,12,16,16,
        16,16,16,14,13,12,
        12,14,13,12,12,14,13,12,
        12,16,15,15,14,12,12,12,12,11,11,12,
        12,16,16,12,11,11,12,12,16,16,15,15,
        15,14,12,12,12,12,0xff};
uchar code song4_Time[]={
        8,8,8,4,2,2,
        8,4,2,2,4,2,1,1,
        1,1,1,1,1,2,1,4,2,1,1,
        4,2,1,1,1,1,1,1,1,2,1,
        8,8,8,2,1,1,
        4,2,1,1,4,2,1,1,
        2,1,1,1,1,1,1,4,1,1,1,1,
        1,2,1,1,1,1,1,1,2,1,2,2,
        2,1,1,8,8,8,0xff};
uchar code song5_Tone[]={
  14,14,14,14,13,12,
        12,14,13,12,12,14,13,12,
        12,11,11,11,11,12,9,9,14,13,12,
        12,14,13,12,12,11,11,12,12,16,16,
        16,16,16,14,13,12,
        12,14,13,12,12,14,13,12,
        12,16,15,15,14,12,12,12,12,11,11,12,
        12,16,16,12,11,11,12,12,16,16,15,15,
        15,14,12,12,12,12,0xff};
uchar code song5_Time[]={
        8,8,8,4,2,2,
        8,4,2,2,4,2,1,1,
        1,1,1,1,1,2,1,4,2,1,1,
        4,2,1,1,1,1,1,1,1,2,1,
        8,8,8,2,1,1,
        4,2,1,1,4,2,1,1,
        2,1,1,1,1,1,1,4,1,1,1,1,
        1,2,1,1,1,1,1,1,2,1,2,2,
        2,1,1,8,8,8,0xff};
void delayms(uint ms)
{
        uchar a;
        while(ms--)
        {
                for(a=230;a>0;a--);
        }
}
uchar Busy_Check(void)
{
        uchar LCD_Status;
        rs=0;
        rw=1;
        ep=1;
        _nop_();
        _nop_();
        _nop_();
        _nop_();
        LCD_Status=P0&0x80;
        ep=0;
        return LCD_Status;
}
void lcd_wcmd(uchar cmd)
{
        while(Busy_Check());
        rs=0;
        rw=0;
        ep=0;
        _nop_();
        _nop_();
        P0=cmd;
        _nop_();
        _nop_();
        _nop_();
        _nop_();
        ep=1;
  _nop_();
        _nop_();
        _nop_();
        _nop_();
        ep=0;
}
void lcd_pos(uchar pos)
{
        lcd_wcmd(pos|0x80);
}
void lcd_wdat(uchar dat)
{
        while(Busy_Check());
        rs=1;
        rw=0;
        ep=0;
        P0=dat;
        _nop_();
        _nop_();
        _nop_();
        _nop_();
        ep=1;
  _nop_();
        _nop_();
        _nop_();
        _nop_();
        ep=0;
}
void lcd_init(void)
{
        lcd_wcmd(0x38);
        delayms(1);
        lcd_wcmd(0x0c);
        delayms(1);
        lcd_wcmd(0x06);
        delayms(1);
        lcd_wcmd(0x01);
        delayms(1);
}
void int0() interrupt 0
{
        delayms(100);
        if(INT0==0)
        {
                TR0=0;
                if(song_Index>5)
                {
                        song_Index=5;
                }
                else
                {
                        song_Index ++;
                }
                if(song_Index==1)
                {
                        song_Tone=song2_Tone;
                        song_Time=song2_Time;
                        discode=dis2;
                }
                if(song_Index==2)
                {
                        song_Tone=song3_Tone;
                        song_Time=song3_Time;
                        discode=dis3;
                }
                if(song_Index==3)
                {
                        song_Tone=song4_Tone;
                        song_Time=song4_Time;
                        discode=dis4;
                }
                if(song_Index==4)
                {
                        song_Tone=song5_Tone;
                        song_Time=song5_Time;
                        discode=dis5;
                }
                if(song_Index==5)
                {
                        song_Tone=song1_Tone;
                        song_Time=song1_Time;
                        discode=dis1;
                        song_Index=0;
                }
                TR0=1;
                i=0;
        }
}
void int1() interrupt 2
{
        delayms(100);
        if(INT1==0)
        {
                TR0=0;
                if(song_Index<1)
                {
                        song_Index=0;
                }
                else
                {
                        song_Index --;
                }
                if(song_Index==1)
                {
                        song_Tone=song2_Tone;
                        song_Time=song2_Time;
                        discode=dis2;
                }
                if(song_Index==2)
                {
                        song_Tone=song3_Tone;
                        song_Time=song3_Time;
                        discode=dis3;
                }
                if(song_Index==3)
                {
                        song_Tone=song4_Tone;
                        song_Time=song4_Time;
                        discode=dis4;
                }
                        if(song_Index==4)
                {
                        song_Tone=song5_Tone;
                        song_Time=song5_Time;
                        discode=dis5;
                }
                if(song_Index==5)
                {
                        song_Tone=song1_Tone;
                        song_Time=song1_Time;
                        discode=dis1;
                        song_Index=0;
                }
                TR0=1;
                i=0;
        }
}
void Timer0() interrupt 1
{
        TH0=Tone_tab[Tone_Index]/256;
        TL0=Tone_tab[Tone_Index]%256;
        beep=~beep;
}
void LCD_disp(void)
{
        uchar i;
        lcd_pos(0);
        i=0;
        while(discode!='\0')
        {
                lcd_wdat(discode);
                i++;
        }
        lcd_pos(0x40);
        i=0;
        while(dis!='\0')
        {
                lcd_wdat(dis);
                i++;
        }
}
void int_init(void)
{
        TMOD=0x01;
        ET0=1;
        EX0=1;
        IT0=1;
        EX1=1;
        IT1=1;
        EA=1;
        TR0=0;
}
void main(void)
{
        int_init();
        song_Tone=song1_Tone;
        song_Time=song1_Time;
        discode=dis1;
        lcd_init();
        while(1);
        {
                LCD_disp();
                Tone_Index=song_Tone;
                if(Tone_Index==0xFF)
                {
                        i=0;
                        TR0=0;
                }
                TR0=1;
                delayms(song_Time[Tone_Index]*60);
                TR0=0;
                i++;
        }
}
               
                       
                       
                       
QQ图片20181202233035.png
回复

使用道具 举报

ID:94031 发表于 2018-12-3 10:19 | 显示全部楼层
你给 LCD 2脚VDD应该加上+5v电源
回复

使用道具 举报

ID:421499 发表于 2018-12-3 17:19 | 显示全部楼层
电平跳动都没有,你再检查一下程序
回复

使用道具 举报

ID:438041 发表于 2018-12-3 21:33 | 显示全部楼层
xuyaqi 发表于 2018-12-3 10:19
你给 LCD 2脚VDD应该加上+5v电源

还是没有字符
QQ图片20181203213307.png
回复

使用道具 举报

ID:60469 发表于 2018-12-3 21:41 | 显示全部楼层

给 LCD 2脚VDD应该加上5v电源
回复

使用道具 举报

ID:337883 发表于 2018-12-3 21:47 | 显示全部楼层
我也有同样问题,同求
回复

使用道具 举报

ID:438041 发表于 2018-12-3 21:48 | 显示全部楼层
xuyaqi 发表于 2018-12-3 10:19
你给 LCD 2脚VDD应该加上+5v电源

而且如果加了电源以后,3脚的灯不亮了,说明3脚不运行了
回复

使用道具 举报

ID:438041 发表于 2018-12-3 21:56 | 显示全部楼层
哈喽哈 发表于 2018-12-3 17:19
电平跳动都没有,你再检查一下程序

刚刚检查了一下,确实有点错误,但是还是不能让电平跳动
回复

使用道具 举报

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

本版积分规则

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

Powered by 单片机教程网

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