找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 3079|回复: 0
收起左侧

HT67Fxx单片机C语言控制LCD的源程序

[复制链接]
ID:207932 发表于 2018-5-2 17:01 | 显示全部楼层 |阅读模式
/*****************************************************
                Project:        test lcd
                MCU:                HT67F40
                Clock:        4M(Internal)
                Author:        Alex_wu        
                Date:         20111103
                function: edit for segment0~17 + COM0~3 to drive LCD
                option:
                SysVolt: 3.0V        
                OSC: HIRC        
                WDT: enable        
                SysFreq: 4M
                Vlcd: 3.0V
                PB0/RES: I/O pin        
                Others select by user                                       
******************************************************/
#include "HT67F40.h"
#include "lcd.h"

#pragma        vector TM_ISR @0x14            //1ms timer
const u8 DigitCode[16] = {0x28,0x7e,0xa4,0x64,0x72,0x61,0x21,0x7c,0x20,0x60,0x30,0x23,0xa9,0x26,0xa1,0xb1}; //0~f

#pragma rambank0
u8  DISP8;      //display buffer
u8  DISP9;
u8  DISP10;
u8  DISP11;
u8  DISP12;
u8  DISP13;
u8  DISP14;
u8  DISP15;
u8  DISP16;

u8  time2ms;
u8  SENDDATA;
u8  STATE;
u8  t500ms;
u16 t1s;
u8  hour;
u8  min;
u8  index;
u16 time1s_dis;
u16 time1s;
u8  tmin;

bit time2msflag;
bit t500msflag;
bit t1sflag;
bit poweronflag;

//----------------------main-------------------
void main()
{   
    Chip_Init();

    for(_mp0 = 0x80; _mp0 < 0xff; _mp0++)
          {        
                  _iar0=0;
          }
         
          _dmbp0=1;
          for(_mp1 = 0x80; _mp1 < 0xa0; _mp1++)
          {        
                  _iar1=0;
          }
          _dmbp0=0;
         
    poweronflag=1;
         
    while(1)
    {
            clrwdt1;
            clrwdt2;
      if(time2msflag)
      {
              time2msflag=0;
              DIS_P();
              
              _dmbp0=1;
              _mp1 = 0x88;
              _iar1= DISP8;
              _mp1 = 0x89;
              _iar1= DISP9;
              _mp1 = 0x8a;
              _iar1= DISP10;
              _mp1 = 0x8b;
              _iar1= DISP11;
              _mp1 = 0x8c;
              _iar1= DISP12;
              _mp1 = 0x8d;
              _iar1= DISP13;
              _mp1 = 0x8e;
              _iar1= DISP14;
              _mp1 = 0x8f;
              _iar1= DISP15;
              _mp1 = 0x90;
              _iar1= DISP16;
              _dmbp0=0;
              
              timer_p();
      }
    }        
}
//---------------------------------------------
void Chip_Init()
{
        _cp0c=0;
        _cp1c=0;
        _acerl=0;
        
        _lcdout0=0;          //seg0~7
        _lcdout1=0;          //seg8~15
        _lcdout2=0b11111100; //seg16~17
        _lcdctrl=0b01001111; //1/3 bias1/4 duty
        
        _t0ae=1;
        _ade=0;
        _mf0e=1;
        _tm0c0=0;
        _tm0al=0b11101000;  //1ms
        _tm0ah=0b00000011;
        _tm0c1=0b11000001;
        _t0on=1;
        
        _emi=1;
}
//---------------------------------------------
void timer_p()
{
        if(t1sflag)
        {
                t1sflag=0;
                if(++tmin>=60)
                {
                        tmin=0;
                        if(++min>=60)
                        {
                                min=0;
                                if(++hour>=24)
                                 hour=0;
                        }
                }
        }
}
//---------------------------------------------
void DIS_P()
{  
          if(STATE)
          {
                  index=hour/10;
                  SENDDATA = ~DigitCode[index];
                  dis_p3();
                  
                  index=hour%10;
                  SENDDATA = ~DigitCode[index];
                  dis_p4();
                  
                  index=min/10;
                  SENDDATA = ~DigitCode[index];
                  dis_p5();
                  
                  index=min%10;
                  SENDDATA = ~DigitCode[index];
                  dis_p6();
                  
                  if(!t500msflag)
                    COL_C;
                  else
                    COL_S;  
          }
          else
          {
                  if(poweronflag)
                  {
                          F3_S;
                          G3_S;
                          E3_S;
                          DISP9=0x0f;
                          F4_S;
                          G4_S;
                          E4_S;
                          DISP11=0x0f;
                          COL_S;
                          F5_S;
                          G5_S;
                          E5_S;
                          DISP14=0x0f;
                          F6_S;
                          G6_S;
                          E6_S;
                          DISP16=0x0f;
                  }
                  else
                  {
                    DISP8=0;
                    DISP9=0;
                    DISP10=0;
                    DISP11=0;
                    DISP12=0;
                    DISP13=0;
                    DISP14=0;
                    DISP15=0;
                    DISP16=0;
                    STATE=1;
                  }
          }   
}
//-------------------
void dis_p3()
{
    if(SENDDATA & 0x80)
           C3_S;
          else
           C3_C;
           
          if(SENDDATA & 0x40)
           E3_S;
          else
           E3_C;
           
          if(SENDDATA & 0x10)
           D3_S;
          else
           D3_C;  
           
          if(SENDDATA & 0x08)
           G3_S;
          else
           G3_C;   
           
          if(SENDDATA & 0x04)
           F3_S;
          else
           F3_C;   
           
          if(SENDDATA & 0x02)
           A3_S;
          else
           A3_C;  
           
          if(SENDDATA & 0x01)
           B3_S;
          else
           B3_C;   
}
//-------------------
void dis_p4()
{
    if(SENDDATA & 0x80)
           C4_S;
          else
           C4_C;
           
          if(SENDDATA & 0x40)
           E4_S;
          else
           E4_C;
           
          if(SENDDATA & 0x10)
           D4_S;
          else
           D4_C;  
           
          if(SENDDATA & 0x08)
           G4_S;
          else
           G4_C;   
           
          if(SENDDATA & 0x04)
           F4_S;
          else
           F4_C;   
           
          if(SENDDATA & 0x02)
           A4_S;
          else
           A4_C;  
           
          if(SENDDATA & 0x01)
           B4_S;
          else
           B4_C;   
}
//-------------------
void dis_p5()
{
    if(SENDDATA & 0x80)
           C5_S;
          else
           C5_C;
           
          if(SENDDATA & 0x40)
           E5_S;
          else
           E5_C;
           
          if(SENDDATA & 0x10)
           D5_S;
          else
           D5_C;  
           
          if(SENDDATA & 0x08)
           G5_S;
          else
           G5_C;   
           
          if(SENDDATA & 0x04)
           F5_S;
          else
           F5_C;   
           
          if(SENDDATA & 0x02)
           A5_S;
          else
           A5_C;  
           
          if(SENDDATA & 0x01)
           B5_S;
          else
           B5_C;   
}
//-------------------
void dis_p6()
{
    if(SENDDATA & 0x80)
           C6_S;
          else
           C6_C;
           
          if(SENDDATA & 0x40)
           E6_S;
          else
           E6_C;
           
          if(SENDDATA & 0x10)
           D6_S;
          else
           D6_C;  
           
          if(SENDDATA & 0x08)
           G6_S;
          else
           G6_C;   
           
          if(SENDDATA & 0x04)
           F6_S;
          else
           F6_C;   
           
          if(SENDDATA & 0x02)
           A6_S;
          else
           A6_C;  
           
          if(SENDDATA & 0x01)
           B6_S;
          else
           B6_C;   
}
//---------------------------------------------
//1ms timer
//---------------------------------------------
void TM_ISR()
{
        _t0af=0;
                 
        if(++time2ms>=2)
        {
                time2ms=0;
                time2msflag=1;
               
         if(poweronflag)
         {
                  if(++time1s_dis>=1000) //筿陪2S
                  {
                           time1s_dis=0;
                           poweronflag=0;
                  }
         }
         else
         {
                  if(++t500ms>=250)
           {
                    t500ms=0;
                    t500msflag = ~t500msflag; //皗
                    
                    if(++t1s>=2)
             {
                      t1s=0;
                      t1sflag=1;
             }
           }
         }
        }        
}


0.jpg

全部资料51hei下载地址:
HT67FxxC语言控制LCD.zip (22.31 KB, 下载次数: 15)

评分

参与人数 1黑币 +50 收起 理由
admin + 50 共享资料的黑币奖励!

查看全部评分

回复

使用道具 举报

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

本版积分规则

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

Powered by 单片机教程网

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