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

📄 78f0485.bak

📁 NEC单片机0485的程序
💻 BAK
📖 第 1 页 / 共 2 页
字号:
#pragma SFR
#pragma DI
#pragma EI
#pragma NOP
#pragma HALT
#pragma STOP
#pragma	asm

#pragma interrupt INTTM000 Tmit_1ms
#pragma interrupt INTKR key_down
#pragma interrupt INTRTC rtc_1s

#define LED_DIN_MODE  PM1.6
#define LED_DIN			  P1.6
#define LED_LOAD_MODE	PM1.5
#define LED_LOAD		  P1.5
#define LED_CLK_MODE	PM1.4
#define LED_CLK			  P1.4
#define	SCL_MODE		PM11.1
#define	SDA_MODE		PM11.0
#define	SCL_PIN			P11.1
#define	SDA_PIN			P11.0
#define BUZZERM PM3.3
#define BUZZER P3.3
#define FAILED 0
#define PASSED 1
#define key4 P4.2
#define key3 P4.3
#define key2 P4.0
#define key1 P4.1

#define _a 0x01
#define _b 0x2
#define _c 0x4
#define _d 0x80
#define _e 0x40
#define _f 0x10
#define _g 0x20
const unsigned char distable[16]={_a+_b+_c+_d+_e+_f+00,   //0
	                                00+_b+_c+00+00+00+00,   //1
	                                _a+_b+00+_d+_e+00+_g,   //2
	                                _a+_b+_c+_d+00+00+_g,   //3
	                                00+_b+_c+00+00+_f+_g,   //4
	                                _a+00+_c+_d+00+_f+_g,   //5
	                                _a+00+_c+_d+_e+_f+_g,   //6
	                                _a+_b+_c+00+00+00+00,   //7
	                                _a+_b+_c+_d+_e+_f+_g,   //8
	                                _a+_b+_c+_d+00+_f+_g,   //9
	                                _a+_b+_c+00+_e+_f+_g,   //a
	                                00+00+_c+_d+_e+_f+_g,   //b
	                                00+00+00+_d+_e+00+_g,   //c
	                                00+_b+_c+_d+_e+00+_g,   //d
	                                _a+00+00+_d+_e+_f+_g,   //e
	                                _a+00+00+00+_e+_f+_g    //f
	                               };
const unsigned char ledchar8_tab[10] = {0x7E, 0x30, 0x6D, 0x79, 0x33, 0x5B, 0x5F, 0x70, 0x7F, 0x7B};

unsigned char LedDisData[8],disbuff[20];
unsigned char systime[7]={0x00,0x30,0x08,0x04,0x01,0x01,0x09};
unsigned long LedNum;
unsigned int timecount;
sreg unsigned int TempData;
bit ack_signal,beepflg,keyflg;

/*****************************lcdbuf define**************************/
/*****************************lcdbuf define**************************/
__directmap unsigned char SEG1 = 0xFA40;
__directmap unsigned char SEG2 = 0xFA41;
__directmap unsigned char SEG3 = 0xFA42;
__directmap unsigned char SEG4 = 0xFA43;
__directmap unsigned char SEG5 = 0xFA44;
__directmap unsigned char SEG6 = 0xFA45;
__directmap unsigned char SEG7 = 0xFA46;
__directmap unsigned char SEG8 = 0xFA47;
__directmap unsigned char SEG9 = 0xFA48;
__directmap unsigned char SEG10= 0xFA49;
__directmap unsigned char SEG11 = 0xFA4A;
__directmap unsigned char SEG12 = 0xFA4B;
__directmap unsigned char SEG13 = 0xFA4C;
__directmap unsigned char SEG14 = 0xFA4D;
__directmap unsigned char SEG15 = 0xFA4E;
__directmap unsigned char SEG16 = 0xFA4F;
__directmap unsigned char SEG17 = 0xFA54;
__directmap unsigned char SEG18 = 0xFA55;
__directmap unsigned char SEG19 = 0xFA56;
__directmap unsigned char SEG20 = 0xFA57;
__directmap unsigned char SEG21 = 0xFA58;
__directmap unsigned char SEG22 = 0xFA59;
__directmap unsigned char SEG23 = 0xFA5A;
__directmap unsigned char SEG24 = 0xFA5B;    // 你们好 //
__directmap unsigned char SEG25 = 0xFA5C;
__directmap unsigned char SEG26 = 0xFA5D;    //  你好 //

/*****************************function define**************************/
/*****************************function define**************************/
void init_cpu(void);
void init_total(void);
void init_fountion(void);

void ledinit(void);
void leddriver(void);
void ledsendbyte(unsigned char data_byte);
void leddisplay(void);

unsigned char gettemp(void);

void iic_start(void);
void iic_stop(void);
void iic_sendbyte(unsigned char data_byte);
unsigned char iic_receivebyte(void);
unsigned char iic_sendpage(unsigned char device_addr, unsigned char word_addr, unsigned char *word_data, unsigned char word_acount);
unsigned char iic_receivepage(unsigned char device_addr, unsigned char word_addr, unsigned char *word_data, unsigned char word_acount);
void iic_giveack(unsigned char wgive_bit);

void startmusic(void);
void buzzerdrv(unsigned int time1, unsigned int time2, unsigned char hfreq,unsigned char lfreq); 
void buzzerdrv2(unsigned int time);
void Tmit_1ms(void);
void key_music(void);

void ini_lcd(void);
void display_seg(void);

void clear_display_buff(void);
void temp_display(void);

void delay_100us (void);
void delay_10ms (void);

void ini_rtc(void);
void write_rtc(void);
void read_rtc(void);
void display_rtc(void);
void display_rtc_1(void);
/****************************************MAIN function**************************************/
/****************************************MAIN function**************************************/
void main ()
{
	IMS = 0xCF;
	IXS = 0x0A;
	DI();
	init_cpu();
	init_total();					
	EI();	
	init_fountion();
	while(1)
	{		
		gettemp();
		leddisplay();
		leddriver();				
		WDTE=0xAC;
	}
}

/****************************************INIT foution**************************************/
/****************************************INIT foution**************************************/
void init_cpu(void)
{
	/*system*/
	OSCCTL=0x10;   //8MHZ
	PCC=0x00;
  MCM=0x00; 
  /*H0 timer*/
  TMHMD0=0x31;  //8M/2^6=125kHZ
	/*00 timer*/
  TMMK000=1;
  TMC00=0x0C;
  PRM00=0x01;
  CR000=3999;   //1MS 
  TMIF000=0;
  TMMK000=0;
  /*KEY Interrupt*/
  KRM=0x0F;
  PM4=0x0F;
  PU4=0x0F;
  P4=0x00;
  KRIF=0;        //without inrterrupt
	KRMK=0;        //enable key interrupt
	PM2=0x00;
	PM11=0x00;
	P2=0x00;
	  
}

void init_total(void)
{
	unsigned char  i,iii;
	for(i = 0; i < 8; i++)
	{LedDisData[i] = 0xFF;}
	for (iii=0; iii<20;iii++)
	{disbuff[iii]=0xFF;}
	LedNum = 0x00BC614E;;	
	LED_DIN_MODE=0;
  LED_LOAD_MODE=0;
  LED_CLK_MODE=0;
  LED_DIN=0;
  LED_LOAD=0;
  LED_CLK=0;    // init number led 
  
  BUZZERM=0;   //control buzzer	
  BUZZER=1;
  PM3.2=0;
  P3.2=0;
  
  PF2=0x00;
  PFALL=0x77;
  
}

void init_fountion(void)
{
	ledinit();
	leddisplay();
	leddriver();
	startmusic();	
	ini_lcd();	
	display_seg();	
	ini_rtc();
	write_rtc();
}
/****************************************start music**************************************/
/****************************************start music**************************************/
void startmusic(void)
{	
	timecount = 0x0;
	beepflg = 1;
	TMHMD0|=0x80;
	while(beepflg)
	{
		WDTE = 0xAC;
//		buzzerdrv(0, 75, 34,1);        //1.85kHZ
//		buzzerdrv(75, 185, 34,0);
//		buzzerdrv(185, 260, 30,1);     //2.10kHZ
//		buzzerdrv(260, 370, 30,0);
//		buzzerdrv(370, 445, 26,1);     //2.40kHZ
//		buzzerdrv(445, 555, 26,0);
//		buzzerdrv(555, 630, 22,1);     //2.85kHZ
//		buzzerdrv(630, 1618, 22,0);
//		buzzerdrv2(1618);
		buzzerdrv(0, 60, 34,1);        //1.85kHZ
		buzzerdrv(60, 160, 34,0);
		buzzerdrv(160, 220, 30,1);     //2.10kHZ
		buzzerdrv(220, 320, 30,0);
		buzzerdrv(320, 380, 26,1);     //2.40kHZ
		buzzerdrv(380, 480, 26,0);
		buzzerdrv(480, 540, 22,1);     //2.85kHZ
		buzzerdrv(540, 1540, 22,0);
		buzzerdrv2(1540);
		WDTE = 0xAC;
	}
}

void buzzerdrv(unsigned int time1, unsigned int time2, unsigned char hfreq,unsigned char lfreq) 
{	
	if((timecount > time1) && (timecount <= time2))
	{	
		if (lfreq)
		   {BUZZER=1;}
		else 
		   {BUZZER=0;}
		CMP00 = hfreq;		
	}
}

void buzzerdrv2(unsigned int time)
{
	if(timecount > time)
	{
		timecount=0;
		TMHMD0=0x00;//ClrBit(TMHMD0, 0x80);
		beepflg = 0;
	}
}

void Tmit_1ms(void)
{
	timecount++;
}

void key_music(void)
{
	timecount = 0x0;
	beepflg = 1;
	TMHMD0|=0x80;
	while(beepflg)
	  {
		 WDTE = 0xAC;
		 buzzerdrv(0, 74, 26,1);     //2.40kHZ
		 buzzerdrv(74, 1059, 26,0);
		 buzzerdrv2(1059);
		}
}
/****************************************number led**************************************/
/****************************************number led**************************************/
void ledinit(void)
{ 
	LED_LOAD = 0;
	ledsendbyte(0x0C);		//shutdown control
	ledsendbyte(0x01);
	LED_LOAD = 1;
	NOP();
	LED_LOAD = 0;
	ledsendbyte(0x0B);		//scanned limit(8)
	ledsendbyte(0x07);
	LED_LOAD = 1;
	NOP();
	LED_LOAD = 0;
	ledsendbyte(0x09);		//decode enable
	ledsendbyte(0x00);
	LED_LOAD = 1;
	NOP();
	LED_LOAD = 0;
	ledsendbyte(0x0A);		//intensity control
	ledsendbyte(0x0F);
	LED_LOAD = 1;
}

void leddriver(void)
{
	register unsigned char i;
	for(i = 0; i < 8; i++)
	{
		LED_LOAD = 0;
		ledsendbyte(i + 1);
		ledsendbyte(LedDisData[i]);
		LED_LOAD = 1;
	}
}

void ledsendbyte(unsigned char data_byte)
{
	register unsigned char i;
	for(i = 0; i < 8; i++)
	{
		LED_CLK = 0;
		if((data_byte << i) & 0x80)
		{LED_DIN = 1;}
		else
		{LED_DIN = 0;}

⌨️ 快捷键说明

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