接且求助:这个程序怎么改?求高手指点
时间:10-02
整理:3721RD
点击:
单片机内部eeprom的程序,现在只是存一个变量,我想改成存两个变量的,各种试,没成功过,下面是存一个变量的原程序麻烦帮忙看看怎么改,要加什么语句才行?
#include <intrins.h>
#include <reg52.h>
#define uchar unsigned char
#define uint unsigned int
#define RdCommand 0x01
#define PrgCommand 0x02
#define EraseCommand 0x03
#define Error 1
#define Ok 0
#define WaitTime 0x01
sfr ISP_DATA=0xe2;
sfr ISP_ADDRH=0xe3;
sfr ISP_ADDRL=0xe4;
sfr ISP_CMD=0xe5;
sfr ISP_TRIG=0xe6;
sfr ISP_CONTR=0xe7;
sbit dula=P2^6;
sbit wela=P2^7;
uchar code table[]={0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f};
uchar num;
void delay(uint t)
{
uint i,j;
for (i=t;i>0;i--)
for (j=110;j>0;j--);
}
void display(uchar shi,uchar ge)//显示子函数
{
dula=1;
P0=table[shi];
dula=0;
P0=0xff;
wela=1;
P0=0xfe;
wela=0;
delay(5);
dula=1;
P0=table[ge];
dula=0;
P0=0xff;
wela=1;
P0=0xfd;
wela=0;
delay(5);
}
/*============打开 ISP,IAP 功能===================*/
void ISP_IAP_enable(void)
{
EA = 0; //关中断
ISP_CONTR= ISP_CONTR&0x18; //001,100
ISP_CONTR= ISP_CONTR|WaitTime;
ISP_CONTR= ISP_CONTR|0x80;
}
/*==============关闭 ISP,IAP 功能============= */
void ISP_IAP_disable(void)
{
ISP_CONTR = ISP_CONTR&0x7f;
ISP_TRIG = 0x00;
EA = 1;
}
/*============公用的触发代码==================*/
void ISPgoon(void)
{
ISP_IAP_enable();
ISP_TRIG= 0x46;
ISP_TRIG= 0xb9;
_nop_();
}
/*=============字节读取=============*/
unsigned char byte_read(unsigned int byte_addr)
{
ISP_ADDRH=(unsigned char)(byte_addr>>8);
ISP_ADDRL=(unsigned char)(byte_addr&0x00ff);
ISP_CMD =ISP_CMD &0xf8;
ISP_CMD =ISP_CMD |RdCommand;
ISPgoon();
ISP_IAP_disable();
return(ISP_DATA);
}
/*================扇区擦除============*/
void SectorErase(unsigned int sector_addr)
{
uint iSectorAddr;
iSectorAddr=(sector_addr&0xfe00);
ISP_ADDRH=(unsigned char)(iSectorAddr>>8);
ISP_ADDRL=0x00;
ISP_CMD =ISP_CMD&0xf8;
ISP_CMD =ISP_CMD|EraseCommand;
ISPgoon();
ISP_IAP_disable();
}
/*==========字节写===============*/
void byte_write(uint byte_addr,uchar original_data)
{
ISP_ADDRH=(unsigned char)(byte_addr>>8);
ISP_ADDRL=(unsigned char)(byte_addr&0x00ff);
ISP_CMD =ISP_CMD&0xf8;
ISP_CMD =ISP_CMD|PrgCommand;
ISP_DATA=original_data;
ISPgoon();
ISP_IAP_disable();
}
void main()
{
uchar a,b,num1;
TMOD=0x01; //设定定时器0为工作方式1
TH0=(65536-50000)/256;
TL0=(65536-50000)/256;
EA=1;
ET0=1;
TR0=1;
num1=byte_read(0X2000);
if(num1>=60)
num1=0;
while(1)
{
if(num>=20)
{
num=0;
num1++;
SectorErase(0x2200);
byte_write(0x2200,num1);
if(num1==15)
{
num1=0;
}
a=num1/10;
b=num1%10;
}
display(a,b);
}
}
void timer0()interrupt 1
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
num++;
}
#include <intrins.h>
#include <reg52.h>
#define uchar unsigned char
#define uint unsigned int
#define RdCommand 0x01
#define PrgCommand 0x02
#define EraseCommand 0x03
#define Error 1
#define Ok 0
#define WaitTime 0x01
sfr ISP_DATA=0xe2;
sfr ISP_ADDRH=0xe3;
sfr ISP_ADDRL=0xe4;
sfr ISP_CMD=0xe5;
sfr ISP_TRIG=0xe6;
sfr ISP_CONTR=0xe7;
sbit dula=P2^6;
sbit wela=P2^7;
uchar code table[]={0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f};
uchar num;
void delay(uint t)
{
uint i,j;
for (i=t;i>0;i--)
for (j=110;j>0;j--);
}
void display(uchar shi,uchar ge)//显示子函数
{
dula=1;
P0=table[shi];
dula=0;
P0=0xff;
wela=1;
P0=0xfe;
wela=0;
delay(5);
dula=1;
P0=table[ge];
dula=0;
P0=0xff;
wela=1;
P0=0xfd;
wela=0;
delay(5);
}
/*============打开 ISP,IAP 功能===================*/
void ISP_IAP_enable(void)
{
EA = 0; //关中断
ISP_CONTR= ISP_CONTR&0x18; //001,100
ISP_CONTR= ISP_CONTR|WaitTime;
ISP_CONTR= ISP_CONTR|0x80;
}
/*==============关闭 ISP,IAP 功能============= */
void ISP_IAP_disable(void)
{
ISP_CONTR = ISP_CONTR&0x7f;
ISP_TRIG = 0x00;
EA = 1;
}
/*============公用的触发代码==================*/
void ISPgoon(void)
{
ISP_IAP_enable();
ISP_TRIG= 0x46;
ISP_TRIG= 0xb9;
_nop_();
}
/*=============字节读取=============*/
unsigned char byte_read(unsigned int byte_addr)
{
ISP_ADDRH=(unsigned char)(byte_addr>>8);
ISP_ADDRL=(unsigned char)(byte_addr&0x00ff);
ISP_CMD =ISP_CMD &0xf8;
ISP_CMD =ISP_CMD |RdCommand;
ISPgoon();
ISP_IAP_disable();
return(ISP_DATA);
}
/*================扇区擦除============*/
void SectorErase(unsigned int sector_addr)
{
uint iSectorAddr;
iSectorAddr=(sector_addr&0xfe00);
ISP_ADDRH=(unsigned char)(iSectorAddr>>8);
ISP_ADDRL=0x00;
ISP_CMD =ISP_CMD&0xf8;
ISP_CMD =ISP_CMD|EraseCommand;
ISPgoon();
ISP_IAP_disable();
}
/*==========字节写===============*/
void byte_write(uint byte_addr,uchar original_data)
{
ISP_ADDRH=(unsigned char)(byte_addr>>8);
ISP_ADDRL=(unsigned char)(byte_addr&0x00ff);
ISP_CMD =ISP_CMD&0xf8;
ISP_CMD =ISP_CMD|PrgCommand;
ISP_DATA=original_data;
ISPgoon();
ISP_IAP_disable();
}
void main()
{
uchar a,b,num1;
TMOD=0x01; //设定定时器0为工作方式1
TH0=(65536-50000)/256;
TL0=(65536-50000)/256;
EA=1;
ET0=1;
TR0=1;
num1=byte_read(0X2000);
if(num1>=60)
num1=0;
while(1)
{
if(num>=20)
{
num=0;
num1++;
SectorErase(0x2200);
byte_write(0x2200,num1);
if(num1==15)
{
num1=0;
}
a=num1/10;
b=num1%10;
}
display(a,b);
}
}
void timer0()interrupt 1
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
num++;
}
有人帮忙吗?