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

📄 78f0485.bak

📁 NEC单片机0485的程序
💻 BAK
📖 第 1 页 / 共 2 页
字号:
		LED_CLK = 1;
	}
}

void leddisplay(void)
{
	LedNum = (TempData >> 8);	
	LedDisData[0] = 0x46;			//T
	LedDisData[1] = 0x4F;			//E
	LedDisData[2] = 0x67;			//P
	LedDisData[3] = 0x0;
	LedDisData[4] = ledchar8_tab[(LedNum / 10) % 10];
	LedDisData[5] = ledchar8_tab[LedNum % 10];
	LedDisData[6] = 0x80;
	LedDisData[7] = ledchar8_tab[(TempData.7 * 5)];
}

/*******************************************I2C Module***************************************/
/*******************************************I2C Module***************************************/
void iic_start(void)
{
	SCL_MODE = 0;
	SDA_MODE = 0;
	SDA_PIN = 1;
	SCL_PIN = 1;
	NOP();
	SDA_PIN = 0;
	SCL_PIN = 0;
}

void iic_stop(void)
{
	SDA_PIN = 0;
	SCL_PIN = 1;
	SDA_PIN = 1;
}

void iic_sendbyte(unsigned char data_byte)
{
	register unsigned char i;
	for(i = 0; i < 8; i++)
	{
		if((data_byte << i) & 0x80)
			{SDA_PIN = 1;}
		else
			{SDA_PIN = 0;}
		SCL_PIN = 1;
		NOP();
		SCL_PIN = 0;
	}
	SDA_MODE = 1;
	SCL_PIN = 1;
	NOP();
	ack_signal = SDA_PIN;
	SDA_MODE = 0;
	SCL_PIN = 0;
}

unsigned char iic_receivebyte(void)
{
	unsigned char data_byte = 0x0;
	register unsigned char i;
	SDA_MODE = 1;
	for(i = 0; i < 8; i++)
	{
		SCL_PIN = 0;
		NOP();
		SCL_PIN = 1;
		data_byte <<= 1;
		data_byte |= SDA_PIN;
	}
	SCL_PIN = 0;
	SDA_MODE = 0;
	return(data_byte);
}


unsigned char iic_sendpage(unsigned char device_addr, unsigned char word_addr, unsigned char *word_data, unsigned char word_acount)
{
	unsigned char i;
	iic_start();
	iic_sendbyte(device_addr);
	if(ack_signal)return FAILED;
	iic_sendbyte(word_addr);
	if(ack_signal)return FAILED;
	for(i = 0; i < word_acount; i++)
	{
		iic_sendbyte(*word_data);
		if(ack_signal)return FAILED;
		word_data++;
	}
	iic_stop();
	return PASSED;
}

unsigned char iic_receivepage(unsigned char device_addr, unsigned char word_addr, unsigned char *word_data, unsigned char word_acount)
{
	unsigned char i;
	iic_start();
	iic_sendbyte(device_addr);
	if(ack_signal)return FAILED;
	iic_sendbyte(word_addr);
	if(ack_signal)return FAILED;
	iic_start();
	iic_sendbyte(device_addr + 1);
	if(ack_signal)return FAILED;
	for(i = 0; i < (word_acount - 1); i++)
		{
			*word_data = iic_receivebyte();
			iic_giveack(0);
			word_data++;
		}
	*word_data = iic_receivebyte();
	iic_giveack(1);
	iic_stop();
	return PASSED;
}


void iic_giveack(unsigned char wgive_bit)
{
	SDA_MODE = 0;
	SDA_PIN = wgive_bit;
	SCL_PIN = 1;
	NOP();
	SCL_PIN = 0;
}

/*******************************************temperature***************************************/
/*******************************************temperature***************************************/
unsigned char gettemp(void)
{
	TempData = 0x0;
	iic_start();
	iic_sendbyte(0x90);			//slave address
	if(ack_signal)return FAILED;
	iic_sendbyte(0x0);			//slave address
	if(ack_signal)return FAILED;
	iic_start();
	iic_sendbyte(0x91);			//slave address
	if(ack_signal)return FAILED;
	TempData |= iic_receivebyte();
	TempData <<= 8;
	iic_giveack(0);
	TempData |= iic_receivebyte();
	iic_giveack(1);
	iic_stop();
	return PASSED;
}

/*******************************************LCD buff***************************************/
/*******************************************LCD buff***************************************/
void ini_lcd(void)
{
	LCDMD=0x00;				//External resistance division method
	//LCDMD=0x30;				//Internal resistance division method (step-down transforming) (Used when VLCD = 3/5VDD) 
	LCDM=0xd0;        //1/4time 1/3bios display off
	LCDC0=0x03;       //LCD_256HZ 32768
	PF2=0x00;         //port2 is port
	PFALL=0x77;       //segment of p8 p9 p10 p14 p15
//	LCDON=1;          //display on
}

void display_seg(void)
{	
	unsigned char *s,i;
	s=&SEG1;
	for(i=0;i<20;i++)
	{s[2*i]=disbuff[i]>>4;
	 s[2*i+1]=disbuff[i]&0xf;}
}

void clear_display_buff(void)
{
	unsigned char m;
	for (m=0; m<20;m++)
	{disbuff[m]=0x00;}
}
void temp_display(void)
{
	SEG26=0x01;
	SEG25=0x09;
	SEG24=0x0F;	
	SEG23=0x0D;
//	SEG22=TempData&0x000f;
//	SEG21=TempData>>12;	
//	SEG20=0x04;
//	SEG19=TempData&0x00f0;
//	SEG18=TempData>>8;
//	SEG15=TempData&0x0f00;
//	SEG14=TempData>>4;
}

/******************************************KEY_operate*************************************/
/******************************************KEY_operate*************************************/
void key_down (void)
{
	keyflg=1;
	if(key4==0)
	{
		delay_10ms ();
		if(key4==0)
		{
			clear_display_buff();
			display_seg();
			NOP();NOP();NOP();NOP();NOP();			
			temp_display();
			key_music();
		}	
	}
	
}

void key_service(void)
{
	
}

/******************************************DELAY*************************************/
/******************************************DELAY*************************************/
void delay_100us (void)
{
	NOP();NOP();NOP();NOP();NOP();NOP();NOP();NOP();NOP();NOP();
	NOP();NOP();NOP();NOP();NOP();NOP();NOP();NOP();NOP();NOP();
	NOP();NOP();NOP();NOP();NOP();NOP();NOP();NOP();NOP();NOP();
	NOP();NOP();NOP();NOP();NOP();NOP();NOP();NOP();NOP();NOP();
}
void delay_10ms (void)
{
	unsigned char mm;
	for (mm=0;mm<10;mm++)
	    {delay_100us();}
}

/******************************************RTC*************************************/
/******************************************RTC*************************************/
void ini_rtc(void)
{
	RTCCL=0x00;   //32768 
	RTCC0=0x2A;   //output 1HZ,24hour,1s interrupt
	RTCC1=0x00;
	RTCC2=0x00; 
	RTCE=1;
	RTCIF=0;
	RTCMK=0;
}

void write_rtc(void)
{
  RWAIT=1;
  SEC  = systime[0];
  MIN  = systime[1];
  HOUR = systime[2];
  WEEK = systime[3];
  DAY  = systime[4];
  MONTH= systime[5];
  YEAR = systime[6];
  RWAIT=0;
}

void read_rtc(void)
{
	RWAIT=1;
  systime[0]= SEC  ;
  systime[1]= MIN  ;
  systime[2]= HOUR ;
  systime[3]= WEEK ;
  systime[4]= DAY  ;
  systime[5]= MONTH;
  systime[6]= YEAR ;
  RWAIT=0;
}

void rtc_1s (void)
{
	read_rtc();
	clear_display_buff();
	display_seg();
	NOP();NOP();NOP();NOP();NOP();
	display_rtc();
	//display_rtc_1();	
}

void display_rtc(void)
{
	unsigned char i;
	SEG25=0x02;
	SEG13=SEG20=0x06;
	for (i=0;i<3;i++)
	{
		disbuff[2*i]=systime[i]&0x0F;
	  disbuff[2*i+1]=systime[i]>>4;
	}
	SEG24=distable[disbuff[0]]&0x07;
	SEG23=distable[disbuff[0]]>>4;
	SEG22=distable[disbuff[1]]&0x07;
	SEG21=distable[disbuff[1]]>>4;
	SEG19=distable[disbuff[2]]&0x07;
	SEG18=distable[disbuff[2]]>>4;
	SEG15=distable[disbuff[3]]&0x07;
	SEG14=distable[disbuff[3]]>>4;
	SEG12=distable[disbuff[4]]&0x07;
	SEG11=distable[disbuff[4]]>>4;
	SEG10=distable[disbuff[5]]&0x07;
	SEG9=distable[disbuff[5]]>>4;	
}

void display_rtc_1(void)
{
	unsigned char i;
	SEG25=0x04;
	SEG2=distable[2]&0x07;
	SEG1=distable[2]>>4;
	SEG4=distable[0]&0x07;
	SEG3=distable[0]>>4;
	
	for (i=0;i<4;i++)
	{
		disbuff[2*i]=systime[i+3]&0x0F;
	  disbuff[2*i+1]=systime[i+3]>>4;
	}
	SEG24=distable[disbuff[0]]&0x07;
	SEG23=distable[disbuff[0]]>>4;
	SEG22=distable[disbuff[1]]&0x07;
	SEG21=distable[disbuff[1]]>>4;
	SEG19=distable[disbuff[2]]&0x07;
	SEG18=distable[disbuff[2]]>>4;
	SEG15=distable[disbuff[3]]&0x07;
	SEG14=distable[disbuff[3]]>>4;
	SEG12=distable[disbuff[4]]&0x07;
	SEG11=distable[disbuff[4]]>>4;
	SEG10=distable[disbuff[5]]&0x07;
	SEG9=distable[disbuff[5]]>>4;
	SEG8=distable[disbuff[6]]&0x07;
	SEG7=distable[disbuff[6]]>>4;
	SEG6=distable[disbuff[7]]&0x07;
	SEG5=distable[disbuff[7]]>>4;
}

⌨️ 快捷键说明

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