目前使用MPC82G516開法板
在網路上有找到驅動如下
但是MCU是STC89C58RD
想請問各位高手知道如何修改成MPC82G516可以使用
/********************************************************************
//? ? ??STC?????FLASH????
//? ? ?????? ??:2006-4-11 16:13
//? ? ?: ??:
//?????
//[???????????C????????
//????: STC89C58RD 50MHz?????????? ??????0.12us
//? ?:
//? ??V1.0
?????????
********************************************************************/
#include <absacc.h>
#include <intrins.h>
#include "REG_MPC82G516.H"
#define u_char unsigned char
#define u_int unsigned int
/* ???? */
sbit SDA=P0^6;
sbit SCL=P0^7;
sbit cs=P0^2;
sbit da=P0^4;
sbit wr=P0^3;
#define true 1
#define false 0
/* ???????????????? */
const u_char code number_code[23] = {
0xd7, /* 0 */
0x50, /* 1 */
0xb5, /* 2 */
0xf1, /* 3 */
0x72, /* 4 */
0xe3, /* 5 */
0xe7, /* 6 */
0x51, /* 7 */
0xf7, /* 8 */
0x73, /* 9 */
0x77, /*a*/
0xe6, /*b*/
0x87, /*c*/
0xf4, /*d*/
0xa7, /*e*/
0x27, /*f*/
0x76, /*h*/
0x86, /*l*/
0x57, /*n*/
0xa6, /*t*/
0x20, /*-*/
0x00, /* ?*/
0xff, /*??*/
};
const u_char code number_code1[23] = {
0xdf, /* 0 */
0x58, /* 1 */
0xbd, /* 2 */
0xf9, /* 3 */
0x7a, /* 4 */
0xeb, /* 5 */
0xef, /* 6 */
0x59, /* 7 */
0xff, /* 8 */
0x7b, /* 9 */
0x77, /*a*/
0xe6, /*b*/
0x87, /*c*/
0xf4, /*d*/
0xa7, /*e*/
0x27, /*f*/
0x76, /*h*/
0x86, /*l*/
0x57, /*n*/
0xa6, /*t*/
0x20, /*-*/
0x00, /* ?*/
0xff, /*??*/
};
/********90614???********/
void I2CWait(void);
bit I2CStart(void);
void I2CStop(void);
void I2CAck(void);
void I2CNoAck(void);
bit I2CWaitAck(void);
void I2CSendByte(u_char demand);
u_char I2CReceiveByte(void);
void I2CReadDate_90614(void);
void system_init(void); /* ??????? */
void lcdinitialize(void);
void wrcom(u_char command);
void startwrdata(u_char adderess ,u_char sdata1,u_char sdata2,u_char sdata3,u_char sdata4);
void clear_led(void); /* ??6?????? */
void full_led(void); /* 6??????? */
void delayms(u_int ms);
void delayus (u_int us);
u_char date[3];
void delay(u_int gj)
{
u_int i;
for(i=0;i<gj;i++)
{
_nop_();
}
}
/*********I2C??***********/
void I2CWait(void)
{
_nop_();_nop_();_nop_();_nop_();_nop_();
}
/********??90614?I2C??********/
bit I2CStart(void)
{
SDA=1;
SCL=1;
I2CWait();
if(!SDA)return false;//SDA?????????,??
SDA=0;
I2CWait();
while(SDA)return false;//SDA??????????,??
SCL=0;
I2CWait();
return true;
}
/********??90614?I2C??*******/
void I2CStop(void)
{
SDA=0;
SCL=0;
I2CWait();
SCL=1;
I2CWait();
SDA=1;
}
/*********?? ACK*********/
void I2CAck(void)
{
SDA=0;
SCL=0;
I2CWait();
SCL=1;
I2CWait();
SCL=0;
}
/*********??NO ACK*********/
void I2CNoAck(void)
{
SDA=1;
SCL=0;
I2CWait();
SCL=1;
I2CWait();
SCL=0;
}
/*********??ACK??*********/
bit I2CWaitAck(void) //???:1=?ACK,0=?ACK
{
u_char errtime=255;
SCL=0;
SDA=1;
I2CWait();
SCL=1;
I2CWait();
while(SDA)
{
errtime--;
if(!errtime)
SCL=0;
return false;
}
SCL=0;
return true;
}
/************MCU?90614??????*************/
void I2CSendByte(u_char demand) //????????//
{
u_char i=8;
while(i--)
{
SCL=0;
_nop_();
SDA=(bit)(demand&0x80);
demand<<=1;
I2CWait();
SCL=1;
I2CWait();
}
SCL=0;
}
/*********MCU?90614?????*********/
u_char I2CReceiveByte(void) //????????//
{
u_char i=8;
u_char ddata=0;
SDA=1;
while(i--)
{
ddata<<=1; //?????????
SCL=0;
I2CWait();
SCL=1;
I2CWait(); //????? ddata|=SDA;ddata<<=1
if(SDA)
{
ddata|=0x01;
}
}
SCL=0;
return ddata;
}
/******?90614???????******/
void I2CReadDate_90614(void)
{
u_char n;
I2CStart();
I2CSendByte(0x00); //5A<<1 wirter
I2CWaitAck();
I2CSendByte(0x07); //Tobj1
I2CWaitAck();
I2CStart();
I2CSendByte(0x01); //(5A<<1)+1 read
I2CWaitAck();
for(n=0;n<3;n++)
{
date[n]=I2CReceiveByte();
if (n!=2) //?????????
{
I2CAck();
}
}
I2CNoAck();
I2CStop();
}
/* ??????? */
void system_init(void)
{
lcdinitialize();
full_led();
delayms(1000);
clear_led();
EA = 0;
SCON = 0x48;
PCON = 0x00;
TMOD = 0x21;
TCON = 0x54;
TH1 = 0xFA; /* ????4800 */
TL1 = 0xFA;
TR1 = 1; /* ???1????*/
TH0 = -(46080 / 256);/* ??50??*/
TL0 = -(46080 % 256);
TR0 = 0; /* ???0????*/
ES = 0; /* ????? */
ET0 = 0; /* ???0??? */
PT0 = 0; /* ??????? */
PS = 0; /* ?????? */
REN = 0; /* ?????? */
IT0=0;
IT1=0;
EX0 = 0; /*????0???*/
EX1=0; /*????1???*/
EA = 0; /* ?CPU?? */
}
void lcdinitialize(void)
{
delayms(500);
wrcom(0x29);//???
wrcom(0x18); //??RC
wrcom(0x01); //????
wrcom(0x03); //???
wrcom(0x80); //??WDT??????
wrcom(0x08); //???
wrcom(0x04); //????
wrcom(0x05); //?WDT
}
void wrcom(u_char command)
{ unsigned char i;
cs=1;
delayus(5);
cs=0;
delayus(5);
wr=0;
delayus(5);
da=1;
delayus(5);
wr=1;
delayus(5);
wr=0;
delayus(5);
da=0;
delayus(5);
wr=1;
delayus(5);
wr=0;
delayus(5);
da=0;
delayus(5);
wr=1;
delayus(5);
CY=0;
for(i=8;i>0;i--)
{
delayus(5);
wr=0;
delayus(5);
if(command&0x80)
{
da=1;
delayus(5);
}
else
{
da=0;
delayus(5);
}
delayus(5);
wr=1;
delayus(5);
command=command<<1;
}
delayus(5);
wr=0;
delayus(5);
da=0;
delayus(5);
wr=1;
delayus(5);
}
void wrdata(u_char adderess ,u_char sdata1,u_char sdata2,u_char sdata3,u_char sdata4)
{
u_char i;
u_char temp1;
u_char temp2;
u_char temp3;
u_char temp4;
temp1 = number_code[sdata1];
temp2 = number_code[sdata2];
temp3 = number_code[sdata3];
temp4 = number_code1[sdata4];
cs=1;
delayus(1);
cs=0;
delayus(1);
wr=0;
delayus(1);
da=1;
delayus(1);
wr=1;
delayus(1);
wr=0;
delayus(1);
da=0;
delayus(1);
wr=1;
delayus(1);
wr=0;
delayus(1);
da=1;
delayus(1);
wr=1;
//adderess=adderess<<2;
for(i=6;i>0;i--)
{
delayus(1);
wr=0;
delayus(1);
if(adderess&0x80)
{
da=1;
delayus(1);
}
else
{
da=0;
delayus(1);
}
wr=1;
delayus(1);
}
for(i=8;i>0;i--)
{
delayus(1);
wr=0;
delayus(1);
if(temp1&0x01)
{
da=1;
delayus(1);
}
else
{
da=0;
delayus(1);
}
delayus(1);
wr=1;
temp1=temp1>>1;
}
for(i=8;i>0;i--)
{
delayus(1);
wr=0;
delayus(1);
if(temp2&0x01)
{
da=1;
delayus(1);
}
else
{
da=0;
delayus(1);
}
delayus(1);
wr=1;
temp2=temp2>>1;
}
for(i=8;i>0;i--)
{
delayus(1);
wr=0;
delayus(1);
if(temp3&0x01)
{
da=1;
delayus(1);
}
else
{
da=0;
delayus(1);
}
delayus(1);
wr=1;
temp3=temp3>>1;
}
for(i=8;i>0;i--)
{
delayus(1);
wr=0;
delayus(1);
if(temp4&0x01)
{
da=1;
delayus(1);
}
else
{
da=0;
delayus(1);
}
delayus(1);
wr=1;
temp4=temp4>>1;
}
}
/* ??4?????? */
void clear_led(void)
{
wrdata(0x00,21,21,21,21);
}
/* 4??????? */
void full_led(void)
{
wrdata(0x00,22,22,22,22);
}
/* ??????????? */
void display_tempreture(u_int tempreture)
{
u_char numb1;
u_char numb2;
u_char numb3;
u_char numb4;
numb1=tempreture/1000;
numb2=(tempreture%1000)/100;
numb3=((tempreture%1000)%100)/10;
numb4=tempreture%10;
wrdata(0x00,numb1,numb2,numb3,numb4);
}
void delayms(u_int ms)/* ????? */
{
u_char i;
while(ms--)
{
for (i=0; i<125; i++);
}
}
void delayus (u_int us)
{
while (us--);
}
void main(void)
{
u_int tempr;
u_int tempr1;
delay(65530);
system_init();
while(1)
{
delay(6553);
I2CReadDate_90614();
tempr1 = date[0]+(date[1]*256);
tempr = (tempr1/5)-2731;
display_tempreture(tempr);
}
}
|
|