您当前的位置:五五电子网电子知识单片机-工控设备义隆单片机EM78P468 NTC lcd测温设计C语言源代码 正文
EM78P468 NTC lcd测温设计C语言源代码

EM78P468 NTC lcd测温设计C语言源代码

点击数:7709 次   录入时间:03-04 12:00:35   整理:http://www.55dianzi.com   义隆单片机

来源:HANTA (suzhou) LTD    作者:Sunli

/********************************************************
 *  Description: 468N RC temperature                    *
 *  Company:     HANTA (suzhou) LTD.                  *
 *  Author:      Sunli                     *
 *  Date:        03/09/2007
 *  最后更新日期:13/09/2007                            *
 * Version:     v1.0                                   *
 *******************************************************/

#i nclude "em78x468xx.h"
#i nclude "table.h"

#define DISI() _asm{disi}
#define ENI() _asm{eni}
#define SLEP() _asm{slep}
#define NOP() _asm{nop}
#define WDTC() _asm{wdtc}

#define uchar unsigned char
#define ushort unsigned short
#define ulong unsigned long
#define Rp R55
#define Rc R61
#define Rm R60
#define SCL R63
#define SDA R62
#define LOW R65
#define MID R66
#define HI  R67
#define COOL R85
#define HOT  R86
#define COL_RST R87
#define LED R54
#define COOL_IF_L R57==0 //如果COOL关
#define COOL_IF_H R57==1 //如果COOL开
#define HEAT_IF_L R56==0 //如果HEAT关
#define HEAT_IF_H R56==1 //如果HEAT开
#define SCL_L R63=0 //I2总线时钟线
#define SCL_H R63=1
#define SDA_L R62=0 //I2总线数据线
#define SDA_H R62=1
#define Rp_TO_IN P5CR|=0x20;NOP()
#define Rp_TO_OUT P5CR&=0xdf;NOP()
#define SDA_TO_IN P6CR|=0x04; NOP() //设数据线位输入
#define SDA_TO_OUT P6CR&=0xfb; NOP() //设数据线位输出
#define SDA_IF_L R62==0  //如果sda为低
#define SDA_IF_H R62==1   //如果sda为高
#define DELAY_us NOP();NOP();NOP();NOP()
#define PAGE_SIZE 8
#define SIZE 0x00ff
#define ON_OFF    0x1e
#define MODE      0x1d
#define FAN       0x1b
#define INCREASE  0x17
#define DECREASE  0x0f
#define W_ADD_COM 0xa0 //写字节命令及器件地址(根据地址实际情况改变), 1010 A2 A1 A0 0
#define R_ADD_COM 0xa1 //读命令字节及器件地址(根据地址实际情况改变), 1010 A2 A1 A0 1
#define LCD_init(init_v) _asm{mov a,@init_v}\
       _asm{mov %LCDCR,a}


uchar lcd_ram[10]=
{ // 0  , 1  ,  2 , 3 ,  4  ,  5 , 6,   7  , 8 ,  9
 0xdf,0x0e,0xeb,0xaf,0x3e,0xbd,0xfd,0x0f,0xff,0xbf
};

ushort dly;
ushort test_temp[6];
ushort Rm_t,Rc_t;

uchar RC_num,Rmin_p,Rmax_p;
ushort Rmin_t,Rmax_t;
ulong Ttmp;

uchar key_state = 0;//按键值
uchar new_key = 0;
uchar key_tCC = 0;
uchar key_temp= 0;
uchar timer_cnt=0;
uchar r_buf[2];
uchar w_buf[2];
uchar set_temper =0;
uchar fan_st   = 0;
uchar mode_on_off=0;
uchar timer1,times;
//ushort timer;
bit key_flag=0;
bit timer_2ms_ok=0;
bit COL_RST_FLAG=0;
/******************函数声明********************/
void main(void);
void sys_init(void);
void tms(uchar i);
void i2cstart(void);
uchar i2cwt(uchar a);
uchar i2crd(void);
void i2cstop(void);
uchar wt24c(uchar *p, uchar ad, uchar n);
void rd24c(uchar *p_dst, uchar ad_rsc, uchar num);
uchar KeySCAN(void);
void KeyDo(uchar key);
//void   key_find(void);
void display(uchar v,uchar tamp_v,uchar set_tmp);
unsigned char test_temperature(void);
unsigned char Bin1toBcd(unsigned char Xbin1);
/*********************end*********************/

void sys_init(void)
{
 SBPCR=0x17; //rc 2.13mHz,sleep->Idle mode,sub-cLOCk run program
 IRCR=0;  //dISAble IR/PWM,port5 is general i/o
 ISR=0;  //clear count1 interrupt flag bit
 
 P5CR=0xc3;  //port7 is lcd segment,port8 is general i/o
 P6CR=0x00;
 P7CR=0;
 P8CR=0x1f;
 CNT12CR=0x06;
 CNT1PR=5;
 CNT1EN=1;
 HPWTPR=0;
 LPWTPR=0;
 IMR|=0x08;  //enable count1 interrupt
 
// WUCR=0x70; //enable p60~3 wake up
// TCCCR=0x0f; //disable main interrupt,TCC pre-scaler 1:256
 WDTCR=0xff; //0xf7; //disable WDT 
 HLPWTCR=0x77;
 P6PH=0xff;  //enable  port6 internal pull high
 P6OD=0;  //disable por6 open-drain
 P8PH=0xff;  //disable port8 internal pull high
 P6PL=0;  //disable port6 internal pull down

 PORT5=0x00;
 PORT6=0x00;
 PORT8=0x00;
 //变量清零
 COL_RST_FLAG=0;
 
}

void tms(uchar i)
{
 uchar j;
 for(;i>0;i--)
  {
   for(j=0;j<200;j++);
   WDTC();
   }
}


/**********************W/R EEPROM*******************************************/
//起始信号
void i2cstart(void)

 SCL_L; DELAY_us;
    SDA_H; DELAY_us;
    SCL_H; DELAY_us;
    SDA_L; DELAY_us;
    SCL_L; DELAY_us;
}


//把一个字节数据输入器件,并以收到应答信号为止
//写入成功返回1,失败返回0
uchar i2cwt(uchar a)
{   uchar i;
 
    for(i=0;i<8;i++)
    {   SCL_L; DELAY_us;
        if((a<<i)&0x80) SDA_H;
     else SDA_L;
     DELAY_us;
        SCL_H; DELAY_us;
      
    }
    SCL_L; DELAY_us;
    SDA_H; DELAY_us;
    SCL_H; DELAY_us;
 
 SDA_TO_IN;  
 
    if(SDA_IF_L)  //测试有无应答
    { SDA_TO_OUT;
     return(1);  //有应答
    }
    else
    { SDA_TO_OUT;
     return(0);  //无应答
    }
}


//i2c读要调用的函数
//从器件读出一个字节
uchar i2crd(void)
{   uchar i,temp;
          
    for(i=0;i<8;i++)
    {   SCL_L; DELAY_us;
        SDA_H; DELAY_us;    //置数据线接上内部上拉(数据输入方式),此为必须
        SCL_H; DELAY_us;
        temp<<=1;
      
        SDA_TO_IN;  
      
  if(SDA_IF_H) temp+=1;
        DELAY_us;
      
        SDA_TO_OUT;  
 }
    SCL_L; DELAY_us;  //主器件应答脉冲
    SDA_L; DELAY_us;
    SCL_H; DELAY_us;

[1] [2] [3] [4] [5]  下一页


本文关键字:C语言  源代码  义隆单片机单片机-工控设备 - 义隆单片机