DS1302.C(86): error C183: unmodifiable lvalue 这个错误该如何改?利用DS1302显示时间的秒部分
#include<regx52.h>unsignedcharcodetable1[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0...
#include<regx52.h>
unsigned char code table1[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90}; //笔段码
unsigned char code table2[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f}; //位选码
unsigned char TempData[]={0};
#define ds1302_second 0x80
/* #define fen_write 0x82;
#define fen_read 0x83;
#define shi_write 0x84;
#define shi_read 0x85; */
#define ds1302_xiebh 0x8e
#define ds1302_charger 0x90
unsigned char time1[8]={20,11,5,7,17,32,50,6};
unsigned char code time[8];
sbit RES=P1^3;
sbit SCLK=P1^7;
sbit IO=P2^3;
void ds1302_write_byte(unsigned char addr,unsigned char d)
{
unsigned char i=0;
SCLK=0;
RES=1;
addr=addr|0xfe;
for(i=0;i<8;i++)
{
if(addr&0x01)
IO=1;
else
IO=0;
SCLK=1;
SCLK=0;
addr>>=1;
}
for(i=0;i<8;i++)
{
if(d&0x01)
IO=1;
else
IO=0;
SCLK=1;
SCLK=0;
d>>=1;
}
RES=0;
}
unsigned char ds1302_read_byte(unsigned char addr)
{
unsigned char i;
unsigned char temp;
SCLK=0;
RES=1;
addr=addr|0x01;
for(i=0;i<8;i++)
{
if(addr&0x01)
IO=1;
else
IO=0;
SCLK=1;
SCLK=0;
addr>>=1;
}
for(i=0;i<8;i++)
{
temp>>=1;
if(RES)
temp=temp|0x80;
else
temp=temp&0x7f;
SCLK=1;
SCLK=0;
}
RES=0;
return(temp);
}
void ds1302_write_time(void)
{
unsigned char i,temp;
for(i=0;i<8;i++)
{
temp=time1[i]/10;
time[i]=time1[i]%10;
time[i]=time1[i]+temp*16;
}
ds1302_write_byte(ds1302_xiebh,0x00); //关闭写保护
ds1302_write_byte(ds1302_second,0x80); //暂停
ds1302_write_byte(ds1302_charger,0xa9); //涓流充电
ds1302_wrire_byte(ds1302_second,time[1])
}
void ds1302_read_time(void)
{
unsigned char i,temp;
time[1]=ds1302_read_byte(ds1302_second)
for(i=0;i<1;i++)
{
temp=time[i]/10;
time1[i]=time[i]%10;
time[i]=time1[i]+temp*10;
}
}
void disp_time()
{
P27=1; P26=1; P25=0; //秒
P0=0x80;
P27=1; P26=1; P25=1;
P0=tab[time[1]/10];
ys();
P27=1; P26=1; P25=0;
P0=0x40;
P27=1; P26=1; P25=1;
P0=tab[time[1]%10];
}
void main()
{
unsigned char i;
RES=0;SCLK=0;
ds1302_write_time()
while(1)
{
ds1302_read_time();
for(i=0;i<1;i++)
{
TempData[i]=time[i];
}
}
}
顺便麻烦给我讲讲DS1302该如何编程,谢谢各位高手了 展开
unsigned char code table1[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90}; //笔段码
unsigned char code table2[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f}; //位选码
unsigned char TempData[]={0};
#define ds1302_second 0x80
/* #define fen_write 0x82;
#define fen_read 0x83;
#define shi_write 0x84;
#define shi_read 0x85; */
#define ds1302_xiebh 0x8e
#define ds1302_charger 0x90
unsigned char time1[8]={20,11,5,7,17,32,50,6};
unsigned char code time[8];
sbit RES=P1^3;
sbit SCLK=P1^7;
sbit IO=P2^3;
void ds1302_write_byte(unsigned char addr,unsigned char d)
{
unsigned char i=0;
SCLK=0;
RES=1;
addr=addr|0xfe;
for(i=0;i<8;i++)
{
if(addr&0x01)
IO=1;
else
IO=0;
SCLK=1;
SCLK=0;
addr>>=1;
}
for(i=0;i<8;i++)
{
if(d&0x01)
IO=1;
else
IO=0;
SCLK=1;
SCLK=0;
d>>=1;
}
RES=0;
}
unsigned char ds1302_read_byte(unsigned char addr)
{
unsigned char i;
unsigned char temp;
SCLK=0;
RES=1;
addr=addr|0x01;
for(i=0;i<8;i++)
{
if(addr&0x01)
IO=1;
else
IO=0;
SCLK=1;
SCLK=0;
addr>>=1;
}
for(i=0;i<8;i++)
{
temp>>=1;
if(RES)
temp=temp|0x80;
else
temp=temp&0x7f;
SCLK=1;
SCLK=0;
}
RES=0;
return(temp);
}
void ds1302_write_time(void)
{
unsigned char i,temp;
for(i=0;i<8;i++)
{
temp=time1[i]/10;
time[i]=time1[i]%10;
time[i]=time1[i]+temp*16;
}
ds1302_write_byte(ds1302_xiebh,0x00); //关闭写保护
ds1302_write_byte(ds1302_second,0x80); //暂停
ds1302_write_byte(ds1302_charger,0xa9); //涓流充电
ds1302_wrire_byte(ds1302_second,time[1])
}
void ds1302_read_time(void)
{
unsigned char i,temp;
time[1]=ds1302_read_byte(ds1302_second)
for(i=0;i<1;i++)
{
temp=time[i]/10;
time1[i]=time[i]%10;
time[i]=time1[i]+temp*10;
}
}
void disp_time()
{
P27=1; P26=1; P25=0; //秒
P0=0x80;
P27=1; P26=1; P25=1;
P0=tab[time[1]/10];
ys();
P27=1; P26=1; P25=0;
P0=0x40;
P27=1; P26=1; P25=1;
P0=tab[time[1]%10];
}
void main()
{
unsigned char i;
RES=0;SCLK=0;
ds1302_write_time()
while(1)
{
ds1302_read_time();
for(i=0;i<1;i++)
{
TempData[i]=time[i];
}
}
}
顺便麻烦给我讲讲DS1302该如何编程,谢谢各位高手了 展开
4个回答
展开全部
uchar code table[] 是对内部的数据寄存器进行赋值 里面的内容只可读不可写, 你要是想往读写数据的话 直接定义数组就可以了 uchar table[] 或者 ucahr data table[]
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
这个错误很隐蔽,他们说的很对,code定义的内容只能读,不能该,要想改除非定义时去掉code。可以看看http://blog.sina.com.cn/s/blog_6fcf7c580100wp9l.html
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
这个因为你用了code,你可以把code改为data..
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询