微波EDA网,见证研发工程师的成长!
首页 > 研发问答 > 嵌入式设计讨论 > MCU和单片机设计讨论 > 用lcd12864控制显示下载程序后没有反应

用lcd12864控制显示下载程序后没有反应

时间:10-02 整理:3721RD 点击:
  具体程序如下,大家帮忙看看指导一下,在此谢谢了
/////////////////////////////////////
//  Generated Initialization File  //
/////////////////////////////////////
#include "C8051F330.h"
#include <intrins.h>
#include <string.h>
#include <stdio.h>
#include <math.h>
#define uchar unsigned char
#define uint unsigned int
#define n_max 120  //采样点个数
#define Lcd_Bus P1
sbit RS=P0^5;
sbit RW=P0^6;
sbit E=P0^7;
sbit PSB=P0^0;
sbit RST=P0^2;
uchar xdata smp[n_max];
uchar xdata lvbo[80] ;
uint  result;
uint  n;
void DrawPoint(uchar X,uchar Y,uchar Color);
void ceshi();
void clrscreen();
unsigned int AdResult, n;
// Peripheral specific initialization functions,
// Called from the Init_Device() function
void PCA_Init()
{
    PCA0MD    &= ~0x40;
    PCA0MD    = 0x00;
}
void Timer_Init()
{
    TMOD      = 0x01;
    TL0       = 0x0C;
    TH0       = 0x10;
}
void ADC_Init()
{
    AMX0P     = 0x03;
    AMX0N     = 0x11;
    ADC0CN    = 0x81;
}
void Port_IO_Init()
{
    P0MDIN    = 0xF7;
    P0SKIP    = 0xED;
    P1SKIP    = 0xFF;
    XBR1      = 0x40;
}
void Oscillator_Init()
{
    OSCICN    = 0x83;
}
void Interrupts_Init()
{
    IE        = 0x82;
    EIE1      = 0x08;
}
// Initialization function for device,
// Call Init_Device() from your main program
void Init_Device(void)
{
    PCA_Init();
    Timer_Init();
    ADC_Init();
    Port_IO_Init();
    Oscillator_Init();
    Interrupts_Init();
}
void Time0_Interrupt() interrupt 1    //定时器0 的中断 中断优先级为1
{
TR0 = 0;
    TL0 = 0x0c;
    TH0 = 0x10;
TR0 = 1;
}
void ADC0_Interrupt() interrupt 10   //ADC的中断,中断优先级为10
{
EIE1  = 0x00;
AD0INT = 0;

AdResult = ADC0H * 256 + ADC0L;
   ceshi();
    clrscreen();
   DrawPoint(56, 55,1);
    DrawPoint(57, 55,1);
     DrawPoint(58, 55,1);
      DrawPoint(59, 55,1);
DrawPoint((n % 128), (result / 20),1);
  DrawPoint(56, 55,1);
    DrawPoint(57, 55,1);
     DrawPoint(58, 55,1);
      DrawPoint(59, 55,1);
n++;
EIE1 = 0x08;
}
/*------------------检查忙位-----------------------------*/
void chk_busy()
{
    RS=0 ;
    RW=1 ;
    E=1 ;
    Lcd_Bus=0xff ;
    while((Lcd_Bus&0x80)==0x80);
    E=0 ;
}
/*------------------延时子程序-----------------------------*/
void delay(unsigned int t)
{
    unsigned int i,j ;
    for(i=0;i<t;i++)
    for(j=0;j<10;j++);
}
/*------------------写命令到LCD------------------------------*/
void write_com(unsigned char cmdcode)
{
    chk_busy();
    RS=0 ;
    RW=0 ;
    E=1 ;
    Lcd_Bus=cmdcode ;
_nop_();
_nop_();
_nop_();
    delay(5);
    //------------------在数据写入的时候加入适当的延时
    E=0 ;
    delay(5);
}
/*-------------------写数据到LCD----------------------------*/
void write_data(unsigned char Dispdata)
{
    chk_busy();
    RS=1 ;
    RW=0 ;
    E=1 ;
    Lcd_Bus=Dispdata ;
  _nop_();
_nop_();
_nop_();
    delay(5);
    //------------------在数据写入的时候加入适当的延时
    E=0 ;
    delay(5);
}
/*------------------初始化LCD屏--------------------------*/
void lcdreset()
{
    delay(10);
PSB = 1;  
RST = 1;  
delay(10);     //并口方式
RST = 0;   //液晶复位
    delay(10);                  
    RST = 1;      
delay(5);
    write_com(0x30);
    delay(50);
    //选择基本指令集
    write_com(0x30);
    //选择8bit数据流
    delay(20);
    write_com(0x01);
    //清除显示,并且设定地址指针为00H
    delay(50);
    write_com(0x06);
    //指定在资料的读取及写入时,设定游标的移动方向及指定显示的移位
    delay(5);
  write_com(0x0c);
    //开显示(无游标、不反白)
    delay(10);
}
/*------------------显示字符串--------------------------*/
void hzkdis(unsigned char code*s)
{
    while(*s>0)
    {
        write_data(*s);
        s++;
        delay(50);
    }
}
/*------------------首屏显示--------------------------*/
void ceshi()
{
    write_com(0x01);
    //清除显示,并且设定地址指针为00H
    delay(50);
   
    write_com(0x80);
    //第一行(如果是地址是:80H,即LCD的第一行的第一个位置显示)
    hzkdis("东大");
   
    write_com(0x90);
    //第二行(如果是地址是:90H,即LCD的第二行的第一个位置显示)
    hzkdis("08班的");
   
    write_com(0x88);
    //第三行(如果是地址是:88H,即LCD的第二行的第一个位置显示)
    hzkdis("心电");
   
    write_com(0x98);
    //第四行(如果是地址是:98H,即LCD的第二行的第一个位置显示)
    hzkdis("波形");
}
//------------------清整个GDRAM空间----------------------------
void clrgdram()
{
    unsigned char x,y ;
    for(y=0;y<64;y++)
    for(x=0;x<16;x++)
    {
        write_com(0x34);
        write_com(y+0x80);
        //行地址
        write_com(x+0x80);
        //列地址
        write_com(0x30);
        write_data(0x00);
        write_data(0x00);
    }
}
//------------------------------------------------------------
void clrscreen()
{
    write_com(0x01);
    _nop_();
_nop_();
_nop_();
    delay(10);
}
uchar ReadByte(void)
{
    unsigned char byReturnValue ;
    chk_busy();
    Lcd_Bus=0xff ;
    RS=1 ;
    RW=1 ;
    E=0 ;
    E=1 ;
    byReturnValue=Lcd_Bus ;
    E=0 ;
   
    return byReturnValue ;
}
//增加画点子程序
void DrawPoint(uchar X,uchar Y,uchar Color)
{
    uchar Row,Tier,Tier_bit ;
    uchar ReadOldH,ReadOldL ;
    write_com(0x34);
    write_com(0x36);
    Tier=X>>4 ;
    Tier_bit=X&0x0f ;
    if(Y<32)
    {
        Row=Y ;
    }
    else
    {
        Row=Y-32 ;
        Tier+=8 ;
    }
    write_com(Row+0x80);
    write_com(Tier+0x80);
    ReadByte();
    ReadOldH=ReadByte();
    ReadOldL=ReadByte();
    write_com(Row+0x80);
    write_com(Tier+0x80);
    if(Tier_bit<8)
    {
        switch(Color)
        {
            case 0 :
            ReadOldH&=(~(0x01<<(7-Tier_bit)));
            break ;
            case 1 :
            ReadOldH|=(0x01<<(7-Tier_bit));
            break ;
            case 2 :
            ReadOldH^=(0x01<<(7-Tier_bit));
            break ;
            default :
            break ;
        }
        write_data(ReadOldH);
        write_data(ReadOldL);
    }
    else
    {
        switch(Color)
        {
            case 0 :
            ReadOldL&=(~(0x01<<(15-Tier_bit)));
            break ;
            case 1 :
            ReadOldL|=(0x01<<(15-Tier_bit));
            break ;
            case 2 :
            ReadOldL^=(0x01<<(15-Tier_bit));
            break ;
            default :
            break ;
        }
        write_data(ReadOldH);
        write_data(ReadOldL);
    }
    write_com(0x30);
}
void main()
{
uchar colour=1 ;
uchar count=0;
    // uint ADzhi;
    RW=0 ;
Init_Device();
    lcdreset();
    ceshi();
    clrgdram();
    delay(50);
    clrscreen();
TR0 = 1;
n = 0;
while(1);
{

}
}

现在出来了么我也遇到了相同的问题

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top