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

📄 lcd_seg.h

📁 客车车身控制模块 分为仪表部分 前控左 前控右 尾控和中控程序模块
💻 H
📖 第 1 页 / 共 2 页
字号:
#define		pcfclk		PTC_PTC2	//
#define		pcfdat		PTC_PTC3	//

#define 	at24clk		PTD_PTD6
#define 	at24dat		PTD_PTD7
//
#define		pcf_timer	7		//5
#define		at24_timer	26//>20
static unsigned long pcf_total,pcf_sub;
//unsigned long last_sub;//里程最近,上一次的数据
static unsigned char disp_ram[15]={
	0x0,0x0,0x0,0x0,0x0,
	0x0,0x0,0x0,0x0,0x0,
	0x0,0x0,0x0,0x0,0x0,
 };
unsigned char disp_data1,disp_data2,disp_data3,disp_data4,
 disp_data5,disp_data6,disp_data7,disp_data8,disp_data9,disp_data10;
unsigned long licheng_temp=0;
static unsigned long mile_total,mile_sub;
///////////////////////////////////
//函数: void delay_pcf8576(unsigned int i)
//描述: 延时程序
//参数: 时间参数i
//返回值:none
////////////////////////////////////
static void delay_pcf8576(unsigned int i){
	unsigned int j=0;
	while(j<i){j++;}__RESET_WATCHDOG();
}
///////////////////////////////////
//函数: void start_pcf8576(void)
//描述: IIC起始头
//参数: none
//返回值:none
////////////////////////////////////
static void start_pcf8576(void){
	pcfclk=0;delay_pcf8576(pcf_timer);
	pcfdat=1;delay_pcf8576(pcf_timer);
	pcfclk=1;delay_pcf8576(pcf_timer);
	pcfdat=0;delay_pcf8576(pcf_timer);
	pcfclk=0;delay_pcf8576(pcf_timer);
}
///////////////////////////////////
//函数: void stop_pcf8576(void)
//描述: IIC结束
//参数: none
//返回值:none
////////////////////////////////////
static void stop_pcf8576(void){
	pcfdat=0;delay_pcf8576(pcf_timer);
	pcfclk=1;delay_pcf8576(pcf_timer);
	pcfdat=1;delay_pcf8576(pcf_timer);
	pcfclk=0;delay_pcf8576(pcf_timer);
}
///////////////////////////////////
//函数: void ack_pcf8576(void)
//描述: IIC总线ACK
//参数: none
//返回值:none
////////////////////////////////////
static void ack_pcf8576(void){
	pcfclk=0;delay_pcf8576(pcf_timer);
	pcfclk=1;delay_pcf8576(pcf_timer);
	pcfclk=0;delay_pcf8576(pcf_timer);	
}
///////////////////////////////////
//函数: void wr_pcf8576_byte(unsigned char ch)
//描述: 写IIC一个字节
//参数: 字节变量CH
//返回值:none
////////////////////////////////////
static void wr_pcf8576_byte(unsigned char ch){
	unsigned i=8;
	while(i--)
	{
		if(ch&0x80)
		{
		  pcfdat=1;
		}
		else
		{
		  pcfdat=0;
		}
		ch<<=1;delay_pcf8576(pcf_timer);
		pcfclk=1;delay_pcf8576(pcf_timer);
		pcfclk=0;delay_pcf8576(pcf_timer);
	}
	ack_pcf8576();
}

//E2PROM相关操作
///////////////////////////////////
//函数: void at24_start(void)
//描述: e2prom起始头
//参数: none
//返回值:none
////////////////////////////////////
static void at24_start(void)
{
	at24clk=0;delay_pcf8576(at24_timer);	
	at24dat=1;delay_pcf8576(at24_timer);	
	at24clk=1;delay_pcf8576(at24_timer);
	
	at24dat=0;delay_pcf8576(at24_timer);
	at24clk=0;delay_pcf8576(at24_timer);
}
///////////////////////////////////
//函数: void at24_stop(void)
//描述: e2prom停止
//参数: none
//返回值:none
////////////////////////////////////
static void at24_stop(void){
	at24dat=0;delay_pcf8576(at24_timer);
	
	at24clk=1;delay_pcf8576(at24_timer);	
	at24dat=1;delay_pcf8576(at24_timer);
	
	at24clk=0;delay_pcf8576(at24_timer);
}
///////////////////////////////////
//函数: void at24_ack(void)
//描述: e2prom应答
//参数: none
//返回值:none
////////////////////////////////////
static void at24_ack(void){
	unsigned char err=250;
	DDRD_DDRD7=0;
	at24clk=0;delay_pcf8576(at24_timer);
	at24clk=1;
	while(at24dat)
	{
		err--;asm(nop);
		if(!err)
		{
		  DDRD_DDRD7=1;__RESET_WATCHDOG();
		  at24clk=0;delay_pcf8576(at24_timer);
		  return;
		}
	}
	DDRD_DDRD7=1;delay_pcf8576(at24_timer);
	at24clk=0;delay_pcf8576(at24_timer);
}

//1010a2a1a0 r/w|1/0
///////////////////////////////////
//函数: void at24_wr_byte(unsigned char)
//描述: e2prom写一字节
//参数: 一字节
//返回值:none
////////////////////////////////////
static void at24_wr_byte(unsigned char at24_temp){
	unsigned char i=8;
	while(i--)
	{
		if(at24_temp & 0x80)
		{
			at24dat=1;			
		}
		else
		{
			at24dat=0;
		}
		at24_temp<<=1;delay_pcf8576(at24_timer);
		at24clk=1;delay_pcf8576(at24_timer);
		at24clk=0;delay_pcf8576(at24_timer);
	}
	at24_ack();
}
///////////////////////////////////
//函数: unsigned char at24_rd_byte(void)
//描述: e2prom写一字节
//参数: none
//返回值:一字节
////////////////////////////////////
static unsigned char at24_rd_byte(unsigned char f_last){
	unsigned char at24_temp1,i;
	at24_temp1=0x0;i=8;
	DDRD_DDRD7=0;
	while(i--)
	{
		at24_temp1<<=1;
		delay_pcf8576(at24_timer);
		at24clk=1;delay_pcf8576(at24_timer);
		if(at24dat) at24_temp1++;
		delay_pcf8576(at24_timer);
		at24clk=0;
		if(i) delay_pcf8576(at24_timer);
	}
  DDRD_DDRD7=1;
  asm(nop);asm(nop);asm(nop);	
  //send ack
  if(f_last==1) at24dat=1;
  else          at24dat=0;
  delay_pcf8576(at24_timer);
	at24clk=1;
	delay_pcf8576(at24_timer);
	at24clk=0;
	delay_pcf8576(at24_timer);
	
	return at24_temp1;
}
////////////////////////////////////////
///////////////////////////////////
//函数: void at24_rd_all(void)
//描述: 读e2prom全部有用字节
//参数: none
//返回值:pcf_total,pcf_sub
////////////////////////////////////
static void at24_rd_all(void/*unsigned char at24all_temp*/){
	unsigned char at24_all3,at24_all2,at24_all1,at24_all0;
	unsigned char at24_all7,at24_all6,at24_all5,at24_all4;
	unsigned long at24_alltemp0,at24_alltemp1;
	//pcf_total
	at24_start();
	at24_wr_byte(0xa0);
	at24_wr_byte(0x00);
	at24_wr_byte(0x10);
	at24_start();
	at24_wr_byte(0xa1);
	at24_all3=at24_rd_byte(0);
	at24_all2=at24_rd_byte(0);
	at24_all1=at24_rd_byte(0);
	at24_all0=at24_rd_byte(0);
	
	at24_all7=at24_rd_byte(0);
	at24_all6=at24_rd_byte(0);
	at24_all5=at24_rd_byte(0);
	at24_all4=at24_rd_byte(1);
	at24_stop();
	
	at24_alltemp0=at24_all3;
	at24_alltemp0<<=8;at24_alltemp0+=at24_all2;
	at24_alltemp0<<=8;at24_alltemp0+=at24_all1;
	at24_alltemp0<<=8;at24_alltemp0+=at24_all0;
	mile_total=at24_alltemp0;
	
	at24_alltemp1=at24_all7;
	at24_alltemp1<<=8;at24_alltemp1+=at24_all6;
	at24_alltemp1<<=8;at24_alltemp1+=at24_all5;
	at24_alltemp1<<=8;at24_alltemp1+=at24_all4;
	mile_sub=at24_alltemp1;	
	//---可加相关操作
}
///////////////////////////////////
//函数: void at24_wr_all(void)
//描述: 写e2prom全部有用字节
//参数: pcf_total,pcf_sub
//返回值:none
////////////////////////////////////
void at24_wr_all(void){
  unsigned char at24_all3,at24_all2,at24_all1,at24_all0;
	unsigned char at24_all7,at24_all6,at24_all5,at24_all4;
	unsigned long at24_alltemp0,at24_alltemp1;
	//pcf_total
	at24_alltemp0=pcf_total;
	at24_all0=(unsigned char)(at24_alltemp0%0x100);
	at24_all1=(unsigned char)((at24_alltemp0>>8)%0x100);
	at24_all2=(unsigned char)((at24_alltemp0>>16)%0x100);
	at24_all3=(unsigned char)((at24_alltemp0>>24)%0x100);
	//pcf_sub
	at24_alltemp1=pcf_sub;
	at24_all4=(unsigned char)(at24_alltemp1%0x100);
	at24_all5=(unsigned char)((at24_alltemp1>>8)%0x100);
	at24_all6=(unsigned char)((at24_alltemp1>>16)%0x100);
	at24_all7=(unsigned char)((at24_alltemp1>>24)%0x100);
	//
	at24_start();
	at24_wr_byte(0xa0);
	at24_wr_byte(0x00);
	at24_wr_byte(0x10);
	at24_wr_byte(at24_all3);
	at24_wr_byte(at24_all2);
	at24_wr_byte(at24_all1);
	at24_wr_byte(at24_all0);
	
	at24_wr_byte(at24_all7);
	at24_wr_byte(at24_all6);
	at24_wr_byte(at24_all5);
	at24_wr_byte(at24_all4);
	at24_stop();	
}
///////////////////////////////////
//函数: void at24_init(void)
//描述: 写e2prom全部有用字节
//参数: pcf_total,pcf_sub
//返回值:none
////////////////////////////////////
void at24_init(void){
  at24_start();
  at24_wr_byte(0xa0);
	at24_wr_byte(0x00);
	at24_wr_byte(0x10);
	
  at24_wr_byte(0x00);
  at24_wr_byte(0x00);
  at24_wr_byte(0x00);
  at24_wr_byte(0x00);
  
  at24_wr_byte(0x00);
  at24_wr_byte(0x00);
  at24_wr_byte(0x00);
  at24_wr_byte(0x00);
  at24_stop();
  
  pcf_total=0;
  pcf_sub=0;
  last_sub=0;
  
}

//pcf8576相关操作
///////////////////////////////////
//函数: unsigned char pcf8576_conver(unsigned char)
//描述: 数据转换
//参数: 数值
//返回值:状态码  fdgea/bc
////////////////////////////////////
static unsigned char pcf8576_conver(unsigned char i){
	unsigned char j;
	switch(i){
		case 0:j=0b11011011; break;

⌨️ 快捷键说明

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