共2条
1/1 1 跳转至页
CS5460A CS5460A有关问题
问
我利用CS5460A开发一个电量传感器,不知哪里错了,总是从CS5460中读不出来数据,请教大家,怎样才能知道我的程序编写正确了?
先谢过!!! 答 1: 完整校表程式,不好,可以给你,不要见笑QQ357164093
/////////////////////////////////////////////////////////////////////
// 2005/05/03
// file name: k2051c.c
// Author: wdmfhvk
// 电压表
//////////////////////////////////////////////////////////////////////
#include <intrins.h>
#include <AT89X051.H>
#include <k2051h.h>
#include <x5045h.h>
uchar enterf,enteri,entern;
uchar x,y,z;
void main()
{
sdi5615=1;
sani=250;
int5460=1;
up=1;
down=1;
entern=1;
enterflag=0;
downflag=0;
upflag=0;
enterf=0;
entern=0;
enteri=0;
sanflag=0;
sani=254;
wdt();
_nop_();
///////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////
/* xiaodui[0]=ReadData(31); //dc off
xiaodui[1]=ReadData(32);
xiaodui[2]=ReadData(33);
xiaodui[3]=ReadData(34); //zy
xiaodui[4]=ReadData(35);
xiaodui[5]=ReadData(36);
xiaodui[6]=ReadData(37); //ac off
xiaodui[7]=ReadData(38);
xiaodui[8]=ReadData(39);
*/
////////////////////////////////////////////////////////
delay(5);
WriteData(1,1);
WriteData(0x64,0x20);
WriteData(1,0x21);
WriteData(0x93,0x22);
WriteData(0x64,0x90);
WriteData(0x63,0x91);
WriteData(0x6c,0x92);
WriteData(0x6f,0x93);
WriteData(0x76,0x94);
WriteData(0x65,0x95);
WriteData(0x79,0x96);
WriteData(0x66,0x97);
////////////////////////////////////////////////////////////////////
wp=1;_nop_();
WriteSR(0xf0);
init5460();
write6122(0xff,0xff,0xff,0xff);
while(int5460==1);
delay(250);
///////////////////////////////////////////////////////wdt();
while(1)
{ if(enterf==1)
{
wdt();
delay(4);
if(up==0){upflag=1;}
if(enter==0){enterflag=1;}
if(down==0){downflag=1;}
enterp();
}
else
{ wdt();
if(int5460==0){cs=0; _nop_(); _nop_(); write_byte(0x5e,0xff,0xff,0xff);cs=1;display();}
if(enter==0){enterflag=1; }
}
}
}
void display(void) // interrupt 1 //using 0 //定时器0中断显示
{
wdt();
if(enterflag==1)
{
enterflag=0;
enteri++;
if(enteri>=6)
{
enteri=0;
enterf=1;
sanflag=1;
entern=1;
write6122(ptp,ptt,0,ziranshui[1]);
while(enter==0)
{wdt();}
pp=ptp; tt=ptt; number2=ziranshui[1];
}
}
else
{
read_byte(0x16);
bcd(); //扫描转换
write6122(qian,bai,shi,guo);
}
}
void bcd(void)//转换成显示数字
{
if(xx>=10000)
{
xiao=0;
xx=xx/10;
}
else
xiao=0x10;
bcdk();
//if(dianliu>9999){qian=0;bai=ziranshui[0];shi=0x4b;guo=0;}
}
uchar read54608bit(void)//读字节
{
uchar count,redata;
sdi=1;
_nop_();
_nop_();
sdo=1;
for(count=0;count<7;count++)
{
sck=0;
_nop_();
_nop_();
sck=1;
redata=redata|(uchar)sdo;
redata=redata<<1;
}
sck=0;
_nop_();
_nop_();
sdi=0;
_nop_();
_nop_();
sck=1;
redata=redata|(uchar)sdo;
return(redata);
}
void write_byte(uchar command1,uchar command2,uchar command3,uchar command4)//任意地址写字节
{
cs=0;
_nop_();
Write8bit(command1);
Write8bit(command2);
Write8bit(command3);
Write8bit(command4);
cs=1;
}
void read_byte(uchar addres)//任意地址读字节
{
unsigned long xxx;
write_byte(0x5e,0xff,0xff,0xff);
cs=0;
_nop_();
Write8bit(addres);
x=read54608bit();
y=read54608bit();
z=read54608bit();
cs=1;
xxx=x;
xxx=xxx<<8;
xxx=xxx|y;
xxx=xxx<<8;
xxx=xxx|z;
xxx=(xxx)/1974;
xx=(unsigned short int)xxx;
}
void wdt(void)
{
if(init==0)
{
wdtcs=1;
_nop_();
wdtcs=0;
_nop_();
wdtcs=1;
}
}
void init5460()
{
write_byte(0xff,0xff,0xff,0xfe);
write_byte(0x4a,0x0,0x3,0xAC);
write_byte(0x40,0x0,0x0,0x01);//配置
//write_byte(0x42,xiaodui[0],xiaodui[1],xiaodui[2]); //write dc off
write_byte(0x48,0x20,0x0,0);// u zy
write_byte(0x44,0x20,0,0); //write i zy off
//write_byte(0x60,xiaodui[6],xiaodui[7],xiaodui[8]); //write ac off
write_byte(0x74,0x80,0,0); //write ac off
writeonebyte(0xe8);
}
void writeonebyte(uchar command)
{
cs=0;
Write8bit(command);
cs=1;
}
void write6122(uchar command1,uchar command2,uchar command3,uchar command4)
{
lcp=0;
wd6122(command4);
wd6122(command1);
wd6122(command2);
wd6122(command3);
lcp=1;
_nop_();
lcp=0;
_nop_();
sdi=1;
}
void wd6122(unsigned char c)//写字节
{
uchar count;
for(count=0;count<8;count++)
{
sdi=c&0x1;
scp=1;
c=c>>1;
scp=0;
_nop_();
}
}
void enterp()
{
wdt();
if(enterflag==1)
{
if(enteri>=254)
{
enterflag=0;
enteri=0;
enterf=0;
sanflag=0;
savedata();
init=1;
_nop_();
while(1);
_nop_();
_nop_();
}
else
{
enteri++;
}
}
//////////////////////////////////////////////////////////////
else //enterflag=0
////////////////////////////////////////////////////////////
{
if(5<enteri)
{
sani=250;
enteri=0;
sanflag=1;
entern++;
if(entern>2)
{
entern=1;
}
switch(entern)
{
case 1:
{
pp=ptp;
tt=ptt;
number2=ziranshui[1];
}
break;
case 2:
{
pp=ptb;
tt=pta;
number2=ziranshui[2];
}
break;
default:
break;
}
}
if(upflag|downflag){updownp();}
}
//////////////////////////////////////////////////////////////
if(sanflag==1){sanp();}
else
{
bcdk();
}
if(enter==1){enteri=0;}
if(up&down){updowni=250;kspeed=130;kspeedi=0;}
enterflag=0;upflag=0;downflag=0;
write6122(qian,bai,shi,guo);
}
void savedata()
{/*
WriteData(ixl,29);
*/
}
void sanp()
{
if(sani>=250)
{
sani=0;
if(dispon==1)
{
qian=pp;bai=tt;shi=0;guo=number2;dispon=0;
}
else
{
qian=0;bai=0;shi=0;guo=0;dispon=1;
}
}
else
{
sani++;
}
}
void updownp()
{
if(updowni>=kspeed)
{
updowni=0;
kspeedi++;
if(kspeedi>=3)
{
kspeed=2;kspeedi=3;
}
else
{
kspeed=130;
}
if(upflag==1)
{
if(sanflag==1)
{
sanflag=0;
///////////////////////////////////////
switch(entern)
{
case 1:{xx=ix;xiao=0x10; }
break;
case 2:{xx=12*ix;xiao=0;}
break;
default:break;
}
///////////////////////////////////////////////////////////////////////
}
else //san==0
{
switch(entern)
{
case 1:
{
writeonebyte(zt);
writeonebyte(dcoff);
xx=1;
}
break;
case 2:
{writeonebyte(zt);
write_byte(0x44,0x40,0,0); //write i zy off
writeonebyte(aczy);
xx=2;
}
break;
default:break;
}
}
}
else //down==1
{
if(sanflag==1)
{
sanflag=0;
switch(entern)
{
case 1:{xx=ix;xiao=0x10;}
break;
case 2:{xx=12*ix;xiao=0;}
break;
default:break;
}
}
else //san==0
{
switch(entern)
{
case 1:
{
enterf=0;
writeonebyte(0xe8);
read_byte(dcoffv);
WriteData(x,0x100);
WriteData(y,0x101);
WriteData(z,0x102);
xx=3;
}
break;
case 2:
{
read_byte(zy);
xx=x;
WriteData(x,0x104);
WriteData(y,0x105);
WriteData(z,0x106);
WriteSR(0);
}
break;
default:break;
}
}
}
}
else
{
updowni++;
}
}
void bcdk(void)//转换成显示数字
{
qian=xx/1000;
zzz=xx%1000;
bai=zzz/100;
zzz=zzz%100;
shi=zzz/10;
guo=zzz%10;
guo=ziranshui[guo];
shi=ziranshui[shi]|xiao;;
bai=ziranshui[bai];
qian=ziranshui[qian];
if(qian==ziranshui[0])
{
qian=0;
if(bai==ziranshui[0])
{
bai=0;
}
}
}
答 2: 谢谢您!!! 答 3: 真乃热心助人啊!wdmfhvkfei兄真乃是热心助人啊!佩服!
周本宏
先谢过!!! 答 1: 完整校表程式,不好,可以给你,不要见笑QQ357164093
/////////////////////////////////////////////////////////////////////
// 2005/05/03
// file name: k2051c.c
// Author: wdmfhvk
// 电压表
//////////////////////////////////////////////////////////////////////
#include <intrins.h>
#include <AT89X051.H>
#include <k2051h.h>
#include <x5045h.h>
uchar enterf,enteri,entern;
uchar x,y,z;
void main()
{
sdi5615=1;
sani=250;
int5460=1;
up=1;
down=1;
entern=1;
enterflag=0;
downflag=0;
upflag=0;
enterf=0;
entern=0;
enteri=0;
sanflag=0;
sani=254;
wdt();
_nop_();
///////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////
/* xiaodui[0]=ReadData(31); //dc off
xiaodui[1]=ReadData(32);
xiaodui[2]=ReadData(33);
xiaodui[3]=ReadData(34); //zy
xiaodui[4]=ReadData(35);
xiaodui[5]=ReadData(36);
xiaodui[6]=ReadData(37); //ac off
xiaodui[7]=ReadData(38);
xiaodui[8]=ReadData(39);
*/
////////////////////////////////////////////////////////
delay(5);
WriteData(1,1);
WriteData(0x64,0x20);
WriteData(1,0x21);
WriteData(0x93,0x22);
WriteData(0x64,0x90);
WriteData(0x63,0x91);
WriteData(0x6c,0x92);
WriteData(0x6f,0x93);
WriteData(0x76,0x94);
WriteData(0x65,0x95);
WriteData(0x79,0x96);
WriteData(0x66,0x97);
////////////////////////////////////////////////////////////////////
wp=1;_nop_();
WriteSR(0xf0);
init5460();
write6122(0xff,0xff,0xff,0xff);
while(int5460==1);
delay(250);
///////////////////////////////////////////////////////wdt();
while(1)
{ if(enterf==1)
{
wdt();
delay(4);
if(up==0){upflag=1;}
if(enter==0){enterflag=1;}
if(down==0){downflag=1;}
enterp();
}
else
{ wdt();
if(int5460==0){cs=0; _nop_(); _nop_(); write_byte(0x5e,0xff,0xff,0xff);cs=1;display();}
if(enter==0){enterflag=1; }
}
}
}
void display(void) // interrupt 1 //using 0 //定时器0中断显示
{
wdt();
if(enterflag==1)
{
enterflag=0;
enteri++;
if(enteri>=6)
{
enteri=0;
enterf=1;
sanflag=1;
entern=1;
write6122(ptp,ptt,0,ziranshui[1]);
while(enter==0)
{wdt();}
pp=ptp; tt=ptt; number2=ziranshui[1];
}
}
else
{
read_byte(0x16);
bcd(); //扫描转换
write6122(qian,bai,shi,guo);
}
}
void bcd(void)//转换成显示数字
{
if(xx>=10000)
{
xiao=0;
xx=xx/10;
}
else
xiao=0x10;
bcdk();
//if(dianliu>9999){qian=0;bai=ziranshui[0];shi=0x4b;guo=0;}
}
uchar read54608bit(void)//读字节
{
uchar count,redata;
sdi=1;
_nop_();
_nop_();
sdo=1;
for(count=0;count<7;count++)
{
sck=0;
_nop_();
_nop_();
sck=1;
redata=redata|(uchar)sdo;
redata=redata<<1;
}
sck=0;
_nop_();
_nop_();
sdi=0;
_nop_();
_nop_();
sck=1;
redata=redata|(uchar)sdo;
return(redata);
}
void write_byte(uchar command1,uchar command2,uchar command3,uchar command4)//任意地址写字节
{
cs=0;
_nop_();
Write8bit(command1);
Write8bit(command2);
Write8bit(command3);
Write8bit(command4);
cs=1;
}
void read_byte(uchar addres)//任意地址读字节
{
unsigned long xxx;
write_byte(0x5e,0xff,0xff,0xff);
cs=0;
_nop_();
Write8bit(addres);
x=read54608bit();
y=read54608bit();
z=read54608bit();
cs=1;
xxx=x;
xxx=xxx<<8;
xxx=xxx|y;
xxx=xxx<<8;
xxx=xxx|z;
xxx=(xxx)/1974;
xx=(unsigned short int)xxx;
}
void wdt(void)
{
if(init==0)
{
wdtcs=1;
_nop_();
wdtcs=0;
_nop_();
wdtcs=1;
}
}
void init5460()
{
write_byte(0xff,0xff,0xff,0xfe);
write_byte(0x4a,0x0,0x3,0xAC);
write_byte(0x40,0x0,0x0,0x01);//配置
//write_byte(0x42,xiaodui[0],xiaodui[1],xiaodui[2]); //write dc off
write_byte(0x48,0x20,0x0,0);// u zy
write_byte(0x44,0x20,0,0); //write i zy off
//write_byte(0x60,xiaodui[6],xiaodui[7],xiaodui[8]); //write ac off
write_byte(0x74,0x80,0,0); //write ac off
writeonebyte(0xe8);
}
void writeonebyte(uchar command)
{
cs=0;
Write8bit(command);
cs=1;
}
void write6122(uchar command1,uchar command2,uchar command3,uchar command4)
{
lcp=0;
wd6122(command4);
wd6122(command1);
wd6122(command2);
wd6122(command3);
lcp=1;
_nop_();
lcp=0;
_nop_();
sdi=1;
}
void wd6122(unsigned char c)//写字节
{
uchar count;
for(count=0;count<8;count++)
{
sdi=c&0x1;
scp=1;
c=c>>1;
scp=0;
_nop_();
}
}
void enterp()
{
wdt();
if(enterflag==1)
{
if(enteri>=254)
{
enterflag=0;
enteri=0;
enterf=0;
sanflag=0;
savedata();
init=1;
_nop_();
while(1);
_nop_();
_nop_();
}
else
{
enteri++;
}
}
//////////////////////////////////////////////////////////////
else //enterflag=0
////////////////////////////////////////////////////////////
{
if(5<enteri)
{
sani=250;
enteri=0;
sanflag=1;
entern++;
if(entern>2)
{
entern=1;
}
switch(entern)
{
case 1:
{
pp=ptp;
tt=ptt;
number2=ziranshui[1];
}
break;
case 2:
{
pp=ptb;
tt=pta;
number2=ziranshui[2];
}
break;
default:
break;
}
}
if(upflag|downflag){updownp();}
}
//////////////////////////////////////////////////////////////
if(sanflag==1){sanp();}
else
{
bcdk();
}
if(enter==1){enteri=0;}
if(up&down){updowni=250;kspeed=130;kspeedi=0;}
enterflag=0;upflag=0;downflag=0;
write6122(qian,bai,shi,guo);
}
void savedata()
{/*
WriteData(ixl,29);
*/
}
void sanp()
{
if(sani>=250)
{
sani=0;
if(dispon==1)
{
qian=pp;bai=tt;shi=0;guo=number2;dispon=0;
}
else
{
qian=0;bai=0;shi=0;guo=0;dispon=1;
}
}
else
{
sani++;
}
}
void updownp()
{
if(updowni>=kspeed)
{
updowni=0;
kspeedi++;
if(kspeedi>=3)
{
kspeed=2;kspeedi=3;
}
else
{
kspeed=130;
}
if(upflag==1)
{
if(sanflag==1)
{
sanflag=0;
///////////////////////////////////////
switch(entern)
{
case 1:{xx=ix;xiao=0x10; }
break;
case 2:{xx=12*ix;xiao=0;}
break;
default:break;
}
///////////////////////////////////////////////////////////////////////
}
else //san==0
{
switch(entern)
{
case 1:
{
writeonebyte(zt);
writeonebyte(dcoff);
xx=1;
}
break;
case 2:
{writeonebyte(zt);
write_byte(0x44,0x40,0,0); //write i zy off
writeonebyte(aczy);
xx=2;
}
break;
default:break;
}
}
}
else //down==1
{
if(sanflag==1)
{
sanflag=0;
switch(entern)
{
case 1:{xx=ix;xiao=0x10;}
break;
case 2:{xx=12*ix;xiao=0;}
break;
default:break;
}
}
else //san==0
{
switch(entern)
{
case 1:
{
enterf=0;
writeonebyte(0xe8);
read_byte(dcoffv);
WriteData(x,0x100);
WriteData(y,0x101);
WriteData(z,0x102);
xx=3;
}
break;
case 2:
{
read_byte(zy);
xx=x;
WriteData(x,0x104);
WriteData(y,0x105);
WriteData(z,0x106);
WriteSR(0);
}
break;
default:break;
}
}
}
}
else
{
updowni++;
}
}
void bcdk(void)//转换成显示数字
{
qian=xx/1000;
zzz=xx%1000;
bai=zzz/100;
zzz=zzz%100;
shi=zzz/10;
guo=zzz%10;
guo=ziranshui[guo];
shi=ziranshui[shi]|xiao;;
bai=ziranshui[bai];
qian=ziranshui[qian];
if(qian==ziranshui[0])
{
qian=0;
if(bai==ziranshui[0])
{
bai=0;
}
}
}
答 2: 谢谢您!!! 答 3: 真乃热心助人啊!wdmfhvkfei兄真乃是热心助人啊!佩服!
周本宏
共2条
1/1 1 跳转至页
回复
有奖活动 | |
---|---|
【有奖活动】分享技术经验,兑换京东卡 | |
话不多说,快进群! | |
请大声喊出:我要开发板! | |
【有奖活动】EEPW网站征稿正在进行时,欢迎踊跃投稿啦 | |
奖!发布技术笔记,技术评测贴换取您心仪的礼品 | |
打赏了!打赏了!打赏了! |
打赏帖 | |
---|---|
与电子爱好者谈读图四被打赏50分 | |
与电子爱好者谈读图二被打赏50分 | |
【FRDM-MCXN947评测】Core1适配运行FreeRtos被打赏50分 | |
【FRDM-MCXN947评测】双核调试被打赏50分 | |
【CPKCORRA8D1B评测】---移植CoreMark被打赏50分 | |
【CPKCORRA8D1B评测】---打开硬件定时器被打赏50分 | |
【FRDM-MCXA156评测】4、CAN loopback模式测试被打赏50分 | |
【CPKcorRA8D1评测】--搭建初始环境被打赏50分 | |
【FRDM-MCXA156评测】3、使用FlexIO模拟UART被打赏50分 | |
【FRDM-MCXA156评测】2、rt-thread MCXA156 BSP制作被打赏50分 |