📄 2543.c
字号:
/*10.1*/
#pragma small
#include <absacc.h>
#include <reg52.h>
#include <intrins.h>
#include <math.h>
#define uchar unsigned char
#define uint unsigned int
data uchar count;
uint grain,ii;
/*-------2543-------*/
sbit ad43_cs=P1^5;
sbit clk43=P1^2;
sbit din43=P1^3;
sbit dout43=P1^4;
/*-------2543-------*/
sbit clk=P2^1; /*1;*/
sbit din=P2^0;
sbit load=P2^2;
//sbit dout=P2^0;
sbit keyre=P2^4;
sbit led1=P2^5;
sbit led2=P2^6;
sbit led3=P2^7;
sbit led4=P0^7; //p2.4连单独键 p0.3--6 四个连续键
/*--------------*///5045
sbit x25_cs=P1^0;
sbit x25_clk=P3^4; // 5045 6pin
sbit x25_din=P3^5; //5045 5pin //5045 3pin 接vcc ,4pin 接 gnd ,7pin 接 reset ,8pin 接 vcc
sbit x25_dout=P3^3; //5045 2pin
/*--------------*/
bdata uchar ab;
sbit abit0=ab^0; sbit abit1=ab^1; sbit abit2=ab^2; sbit abit3=ab^3;
sbit abit4=ab^4; sbit abit5=ab^5; sbit abit6=ab^6; sbit abit7=ab^7;
/*----------------------------------------------------------------------*/
/*void rst_wdog(void)
{
x25_cs=0;
x25_cs=1;
} */
/*--------------*/
void delay(uchar n)
{
data uchar i,j,k;
for(i=0;i<n;i++)
{
for(j=0;j<250;j++)
{
for(k=0;k<25;k++)
{
//rst_wdog();
}
}
}
}
/*---------------------------------------------------------*/
/*---------------------------------------------------------*/
void dis_7219(uchar iw,uchar ix)
{
uchar i,j,nc;
clk=0;
load=0;
//if(chl==0)load=0;else load2=0;
ab=iw;
for(i=0;i<8;i++){
din=abit7;
ab<<=1;
/*abit0=dout; dout;*/
clk=1;
for(j=0;j<10;j++)nc=0;
clk=0;
}
ab=ix;
for(i=0;i<8;i++){
din=abit7;
ab<<=1;
/*abit0=dout;*/
clk=1;
for(j=0;j<10;j++)nc=0;
clk=0;
}
load=1;
// rst_wdog();
//if(chl==0)load=1; else load2=1;
}
/*---------------------------------------------------------*/
void dis_set(void)
{
data uchar i;
P2=0xff;P3=0xff;P1=0xff;
//for(j=0;j<2;j++){
dis_7219(0x0f,0x0);
dis_7219(0x0A,0x0a);
dis_7219(0x09,0x55); //if(j==0)dis_7219(0x09,0xff,j);else dis_7219(0x09,0xff,j); /*decode mode*/
dis_7219(0x0B,0x06);
dis_7219(0x0C,0x01);
for(i=0;i<7;i++)dis_7219(i,0xf);
// }
//for(i=0;i<4;i++)W[i]=0; W_x=0;Ph[0]=Ph[1]=P_x=0;
}
/*---------------------------------------------------------*/
/*---------------------------------------------------------*/
int ad_2543(uchar n) /*模数转换*/
{
data uchar i,j,ch;
data union{
uchar ch[2];
uint i;
}u;
clk43=0;
ad43_cs=0;
ab=n<<4;
for(j=0;j<10;j++)ch=0;
for(i=0;i<8;i++){
din43=abit7;
ab<<=1;
abit0=dout43; /*dout; dout;*/
for(j=0;j<20;j++)ch=0;
clk43=1;
for(j=0;j<20;j++)ch=0;
clk43=0;
for(j=0;j<20;j++)ch=0;
}
u.ch[0]=ab;
ab=0;
for(i=0;i<4;i++){
ab<<=1;
abit0=dout43;
clk43=1;
for(j=0;j<20;j++)ch=0;
clk43=0;
for(j=0;j<20;j++)ch=0;
}
u.ch[1]=ab<<4;
u.i>>=4;
ad43_cs=1;
//rst_wdog();
return u.i;
}
/*--------------------------------------------------------*/
/*--------------------------------------------------------*/
/*
outbyt:
Sends byte to EEPROM
This routine shifts out a byte, starting with the MSB to the EEPROM
*/
//**************************************************************************************
void outbyt(uchar ib)
{
uchar i;
ab=ib;
for(i=0;i<8;i++){
x25_clk=0;
x25_din=abit7;
ab<<=1;
x25_clk=1;
}
x25_din=0;
}
/*
inbyt:
Receives byte from EEPROM
This routine receives a byte MSB first, from the EEPROM
Output: received byte
*/
uchar inbyt(void)
{
uchar i;
x25_dout=1;
for(i=0;i<8;i++){
x25_clk=1;
x25_clk=0;
ab<<=1;
abit0=x25_dout;
}
return ab;
}
/*
byte read:
Single byte read
This routine sends the command to read asingle byte from the EEPROM
memory array
output : read byte
*/
uchar byte_read(uint loc)
{
uchar ch;
union{
uchar ch[2];
uint i;
}u;
u.i=loc;
x25_clk=0;x25_cs=0;u.ch[0]=((u.ch[0]&0x01)<<3)|0x03;
outbyt(u.ch[0]); /* out read command*/
outbyt(u.ch[1]);
ch=inbyt();
x25_clk=0;
x25_cs=1;
return ch;
}
/*
read N bytes from EEPROM
*/
void read_Nbyte(uchar *str, uint loc,uchar n)
{
uchar i,*p;
union{
uchar ch[2];
uint i;
}u;
u.i=loc;
x25_clk=0;x25_cs=0;u.ch[0]=((u.ch[0]&0x01)<<3)|0x03;
outbyt(u.ch[0]); /* out read command*/
outbyt(u.ch[1]);
p=str;
for(i=0;i<n;i++){
*p++=inbyt();
}
*p=0;
x25_clk=0;x25_cs=1;
}
/*
rdsr_cmd
Read status register
This routine sends the command to read the status register
Output : status register
*/
uchar rdsr_cmd(void)
{
uchar ch;
x25_clk=0;
x25_cs=0;
outbyt(5); /*read status register instruction (rdsr)*/
ch=inbyt(); /*read status register*/
x25_clk=0;
x25_cs=1;
return ch;
}
/*
wip_poll
write in progress polling
This routine polls for completion of a nonvolatile write cycle by
examining the WIP bit of the status register
*/
void wip_poll(void) //功能??????????????
{
uchar i;
for(i=0;i<99;i++){
ab=rdsr_cmd();
if(!abit0) break;
}
i=0;
}
/*
wrsr_cmd
write status register
This routine sends the command to write the WD0 WD1,BP0 and BP) eeprom bits in
the status register
call outbyt wip_poll
*/
void wrsr_cmd(uchar x)
{
x25_clk=0;x25_cs=0;
outbyt(0x06); /*write enable*/ //0xff
x25_cs=1;
x25_clk=0;
x25_cs=0;
outbyt(1); /*write status register with 0x01*/
outbyt(x); /*write status register*/
x25_clk=0;
x25_cs=1;
wip_poll();
}
/*
page write to EEPROM
*/
void page_write(uchar *str,uint loc,uchar n)
{
uchar i,*p;
union{
uchar ch[2];
uint i;
}u;
x25_clk=0;x25_cs=0;
outbyt(0x06); /*write enable*/
x25_cs=1; x25_cs=0;
u.i=loc;
x25_clk=0;x25_cs=0;u.ch[0]=((u.ch[0]&0x01)<<3)|0x02;
outbyt(u.ch[0]); /* out read command*/
outbyt(u.ch[1]);
p=str;
for(i=0;i<n;i++){
outbyt(*p++);
}
x25_clk=0; x25_cs=1;
wip_poll();
}
/*
byte_write:
Single byte write
This routine sends the command to write a single byte to the EEPROM
memory array
*/
//************************************************************************
void byte_write(uint loc,uchar x)
{
union{
uchar ch[2];
uint i;
}u;
x25_clk=0;x25_cs=0;
outbyt(0x06); /*write enable*/ //06为instruct write
x25_cs=1; x25_cs=0;
u.i=loc;
x25_clk=0;x25_cs=0;u.ch[0]=((u.ch[0]&0x01)<<3)|0x02;
outbyt(u.ch[0]); /* out read command*/
outbyt(u.ch[1]);
outbyt(x);
x25_clk=0; x25_cs=1;
wip_poll();
}
/*
Name WREN_CMD
Description: Set write enable latch
Function: This routine sends the command to enable writes to the EEPROM
memory array or status register
call: outbyt
input None
Register Usage A
void wren_cmd(void)
{
sck=0; x25_cs=0;
*/
/*----------------------------------------*/
uchar keyscan(void)
{
data uchar key_p2 ,key,keybuff;
key_p2=P0;
key_p2=P0;
if(keyre==0)
key=5;
else
{
key_p2=key_p2 | 0x87;
switch(key_p2){
case 0xff: key=0;keybuff=key;break;//no key
case 0xbf: key=1;keybuff=key;break;
case 0xdf: key=2;keybuff=key;break;
case 0xef: key=3;keybuff=key;break;
case 0xf7: key=4;keybuff=key;break;
default:break;
}
//delay(1);
key_p2=P0;
key_p2=key_p2 | 0x87;
switch(key_p2){
case 0xff: key=0;if(key!=keybuff)key=0; break;
case 0xbf: key=1;if(key!=keybuff)key=0; break;
case 0xdf: key=2;if(key!=keybuff)key=0; break;
case 0xef: key=3;if(key!=keybuff)key=0; break;
case 0xf7: key=4;if(key!=keybuff)key=0; break;
default:break;
}
}
return key;
}
/*----------------------------------------*/
void digitally_dis( int t,uchar i) //千位 百位 十位 个位entries
{ data uchar thou ,hun,ten,entries, tune;
i=0;
thou=t/1000;
hun= (t-thou*1000 )/100;
ten = (t-thou*1000- hun* 100)/10;
entries= t-thou*1000- hun* 100-ten*10;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -