⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dianlian.c

📁 DSP读写电量监测芯片源代码
💻 C
字号:
#include "bus30.h"
extern cregister volatile int IOF;
extern cregister volatile int IF;
extern cregister volatile int IE;       
extern volatile BUS_REG *p;
extern  int d_b_addr;    
extern unsigned char xizi[][16];   
extern unsigned int shu_cai_flag,flag_flag_flag; 
extern   int main_function;
unsigned int dianlts_chang[] = {32+300,317+300,32+300,35+300,
			       251+300,12+32,78+300,319+300,32+300,
			       1+32,0};/*电池电量低,请充电!*/
char buff_page[9];//" DS2438页0读缓冲区BUFF
char DIANLIANG;//"电量 
char DIANL_MAX=255,DIANL_MIN=10;//差最好能 被11整除;
void delay_zxb(int delay1);
void wtite_byte(char byte);
void read_page();
void INIT();
void read_id();
void read_temp_volt_cur();
void read_dianliang_ica();
void read_dianliang_cca_dca();
void set();
               
void read_id()
{
   INIT();//"复位
   wtite_byte(0X33);
   read_page();
   INIT();//"复位  
}
void set()
{  	 
   //'condiants_flag=0;
   INIT();//"复位
   wtite_byte(0XCC);//"发"跳过ROM" 命令
   wtite_byte(0X4E);//"发"写高速暂存"命令
   wtite_byte(0X01);
   wtite_byte(0X00);
   wtite_byte(0X00);
   wtite_byte(0X00);
   wtite_byte(0X00);
   wtite_byte(0xcc);
   wtite_byte(0X08);
   wtite_byte(0X00);
   wtite_byte(0X00);
   INIT();//"复位
   wtite_byte(0XCC);//"发"跳过ROM" 命令
   wtite_byte(0X48);//"发"写高速暂存"命令
   wtite_byte(0X01);
   delay_zxb(20000);  
   INIT();//"复位
   wtite_byte(0XCC);//"发"跳过ROM" 命令
   wtite_byte(0X4E);//"发"写高速暂存"命令
   wtite_byte(0X00);
   wtite_byte(0X0f);
   INIT();//"复位
   wtite_byte(0XCC);//"发"跳过ROM" 命令
   wtite_byte(0X48);//"发"写高速暂存"命令
   wtite_byte(0X00);
   delay_zxb(20000);  
   INIT();
   wtite_byte(0XCC);
   wtite_byte(0XBE);
   wtite_byte(0X00);   
   read_page();//"读回全部9个字节
   INIT();
}
//"读单总线供电电压子程序 温度转换子程序
void read_temp_volt_cur()
{
  INIT();
  wtite_byte(0XCC);
  wtite_byte(0X44);
  delay_zxb(20000);
  INIT();
  wtite_byte(0XCC);
  wtite_byte(0XB4);
  delay_zxb(20000);
  INIT();
  wtite_byte(0XCC);
  wtite_byte(0XB8);
  wtite_byte(0X00);
  INIT();
  wtite_byte(0XCC);
  wtite_byte(0XBE);
  wtite_byte(0X00);
  read_page();//"读回全部9个字节
  INIT();
}
//"读单总线供电电量子程序
void read_dianliang_ica()
{
  INIT();//"复位
  wtite_byte(0XCC);
  wtite_byte(0XB8);
  wtite_byte(0X01);
  INIT();//"复位
  wtite_byte(0XCC);
  wtite_byte(0XBE);
  wtite_byte(0X01);
  read_page();
  INIT();//"复位
}
void read_dianliang_cca_dca()
{  
  INIT();
  wtite_byte(0XCC);
  wtite_byte(0xB8);
  wtite_byte(0X07);
  INIT();
  wtite_byte(0XCC);
  wtite_byte(0xBE);
  wtite_byte(0X07);
  read_page();
  INIT();
}
//"复位并接收存在脉冲
void INIT()
{
  delay_zxb(3);
  IOF=0X62;
  delay_zxb(130);//"延时520μs
  IOF=0X60;//"释放总线
  delay_zxb(50);
  //if(IOF&0x08==0X08) return;//"无存在脉冲返回
  delay_zxb(130);//"等待存在脉冲结束
}
//"DS2438页(8字节数据+1字节CRC)读子程序
void read_page()
{
  unsigned char i,j,temp,tmp1;
  for(i=0;i<9;i++)
  {//'2981320
    temp=0;
    for(j=0;j<8;j++)
    {
     IOF=0X62;
     asm(" nop ");asm(" nop ");asm(" nop ");asm(" nop ");
     asm(" nop ");asm(" nop ");asm(" nop ");asm(" nop ");
     IOF=0X60;
     tmp1=IOF;
     temp=temp|((tmp1&0X08)<<4);
     if(j<7) temp=temp>>1;
     delay_zxb(16);
    }
    buff_page[i]=temp;
  }  
}
//"DS2438字节写子程序
void wtite_byte(char byte)
{
  unsigned char i,temp;
  for(i=0;i<8;i++)
  {
    temp=byte&0x01;
    if(i<7) byte=byte>>1;
    IOF=0x62;
    if(temp==0)
    {
       delay_zxb(14);
       IOF=0X60;
       delay_zxb(1);
    }
    else
    {  
       asm(" nop ");asm(" nop ");asm(" nop ");asm(" nop ");
       asm(" nop ");asm(" nop ");asm(" nop ");asm(" nop ");
       asm(" nop ");asm(" nop ");asm(" nop ");asm(" nop ");
       IOF=0x60;
       delay_zxb(14);
    }
    delay_zxb(40);
  } 
}

void delay_zxb(int delay1)
{   int i;
for(i=0;i<delay1;i++)                                                                              
		asm(" nop ");
}                
void disp_dianlian_zxb(unsigned int x,unsigned int y,unsigned int flag)//加中断!y=1
{
	unsigned int i,temp1,temp2,temp3;
	//IOF=?
	temp1=IE;
	temp2=IF;
	IE=0X0000;
	p->strb0_gcontrol=0x0f10f8; 
    	p->strb1_gcontrol=0x0f10f8;
    	p->exp_gcontrol=0x58;
	read_dianliang_ica();
	p->strb0_gcontrol=0x0f1058; 
   	p->strb1_gcontrol=0x0f1058;
    	p->exp_gcontrol=0xf8; 
	IOF=0x66;          		
	IF=temp2;			/*!!!!!!!!!!!!!!!*/
	IE=temp1;
	DIANLIANG=buff_page[4]; 
	//'cleawin_new(x,2,x+1,2,2,0x10a0); 	
	/*
	if(main_function == 5) 
	  disint(23,12,buff_page[4],5,2,0x10a0,0); 
	  */ 
	if(flag == 3 && DIANLIANG==0)
	{set();
	 return;
	}
	if(DIANLIANG<DIANL_MIN)
	{	
              cleawin_new(0,0,39,14,0,0x1000);
              Write_Screen_new(9,13,dianlts_chang,83,0x10a0);
              box_new(62,110,220,148,0);
	      if(shu_cai_flag == 1)	    
	          cunchu_struct(1); 
	      //'chunchu_chanshu(1); 
	      if(flag_flag_flag!=0)
              chunchu_boxin_zxb(405,1);
              flash_write_sector(0,0x4000,1);
              //'flash_write_sector(0,0x4000,1);
              IOF = 0x22;
              while(1);  
	}
  if(flag==1)	
  { 
    clear_win_new(230,1,241,18);	  
	lszdr2_new(x,y,&xizi[103][0],1,d_b_addr);
	temp1=(DIANL_MAX-DIANL_MIN)/10; //'如果不能整除?11
	temp2=DIANLIANG-DIANL_MIN;
	temp3=temp2/temp1;	//'取整方向????向零取整
	if(temp3>8)
	{
	line_new(x*8+3,y+4+9,x*8+5,y+4+9,1,0);//??
	temp3=8;
	}
	for(i=0;i<=temp3;i++)
	line_new(x*8,y+4+i,(x+1)*8-1,y+4+i,1,0); 
	//box_new(x*8-1,0,(x+6)*8-1,19,0);//'用画线 	
  }//'line_new(x*8-5,0,x*8-4,20,1,0); 
	//'line_new((x+1)*8+4,0,x*8+4,20,1,0);
	//'line_new(0,19,320,19,1,0); 	
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -