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

📄 main.lss

📁 AVR_DEMO测试程序
💻 LSS
📖 第 1 页 / 共 3 页
字号:
	 

     DDRA |= LCD_DATA ;//
	 //DDRC = 0XFF;
     DDRC |= LCD_RS  | LCD_EN | LCD_RW ; //
      
     LCD_init();//初始化 
 	 

	 
	 delay_ms(200);
	 LCD_write_char(0x01,0);      //显示清屏
 
	 delay_ms(500);
	 
     LCD_write_string(1,0,"WWW.QLMCU.COM"); 
	 delay_ms(200);
     LCD_write_string(1,1,"0595-22313231"); 
	 delay_ms(1000);

	
	Init_IO();//初始化I/O口
	PORTA=0X00;//测试发光二极管
	sbi(DDRD,7);
	LED_ON;
	
	BEEP();//测试蜂鸣器
	delay_ms(500);
	BEEP();
	delay_ms(500);
	BEEP();                  
    delay_ms(2000);//延时
	PORTB=0xff;  //熄灭所有的数码管
	
	LED_OFF;//关闭发光二极管
	PORTA=0XFF;
	
    TCCR0=0x04;//T/C0工作于定时方式,系统时钟256分频
    TCNT0=0x06;//计数初始值6 
    TIMSK=0x02;//开放TOV0中断
    SREG=SREG|0x80;//开放总中断

  while(1)
   {
     Process(Timer,Data);           //计数值处理
     Display(Data);                     //动态扫描显示
   } 
}


//---------------------T/C0中断服务函数-------------------------
SIGNAL(SIG_OVERFLOW0)

{
    TCNT0=0x06;                     //重装计数初始值6
    CNT++;                               //中断次数累加
  if(CNT==125)           
    {CNT=0;                          //计数到125次,计数值复位
     Timer[2]++;                    //秒加1
     if(Timer[2]==60)
        {Timer[2]=0;
         Timer[1]++;
		}              //分进位
       if(Timer[1]==60)
          {Timer[1]=0;
           Timer[0]++;
		  }             //时进位
         if(Timer[0]==24)
            {Timer[0]=0;
			}
    }                                     //计数到达最高位,计数复位
}


//---------------蜂鸣器子程序-------------
void BEEP(void)
{
 12e:	cf 93       	push	r28
 130:	df 93       	push	r29
    unsigned int j;
	sbi(DDRD,2);//把PB2设置为输出(蜂鸣器)
 132:	8a 9a       	sbi	0x11, 2	; 17

	
	  for(j=200;j>0;j--)
 134:	c8 ec       	ldi	r28, 0xC8	; 200
 136:	d0 e0       	ldi	r29, 0x00	; 0
		{
		BEEP_ON;delay_us(500);
 138:	92 98       	cbi	0x12, 2	; 18
 13a:	84 ef       	ldi	r24, 0xF4	; 244
 13c:	91 e0       	ldi	r25, 0x01	; 1
 13e:	9e df       	rcall	.-196    	; 0x7c
		BEEP_OFF;delay_us(40);//2.5KHz
 140:	92 9a       	sbi	0x12, 2	; 18
 142:	88 e2       	ldi	r24, 0x28	; 40
 144:	90 e0       	ldi	r25, 0x00	; 0
 146:	9a df       	rcall	.-204    	; 0x7c
 148:	21 97       	sbiw	r28, 0x01	; 1
 14a:	b1 f7       	brne	.-20     	; 0x138
		}
delay_us(10);
 14c:	8a e0       	ldi	r24, 0x0A	; 10
 14e:	90 e0       	ldi	r25, 0x00	; 0
 150:	95 df       	rcall	.-214    	; 0x7c
	
	  for(j=200;j>0;j--)
 152:	c8 ec       	ldi	r28, 0xC8	; 200
 154:	d0 e0       	ldi	r29, 0x00	; 0
		{
		BEEP_ON;delay_us(600);
 156:	92 98       	cbi	0x12, 2	; 18
 158:	88 e5       	ldi	r24, 0x58	; 88
 15a:	92 e0       	ldi	r25, 0x02	; 2
 15c:	8f df       	rcall	.-226    	; 0x7c
		BEEP_OFF;delay_us(40);//1.25KHz
 15e:	92 9a       	sbi	0x12, 2	; 18
 160:	88 e2       	ldi	r24, 0x28	; 40
 162:	90 e0       	ldi	r25, 0x00	; 0
 164:	8b df       	rcall	.-234    	; 0x7c
 166:	21 97       	sbiw	r28, 0x01	; 1
 168:	b1 f7       	brne	.-20     	; 0x156
		}
delay_us(5);		
 16a:	85 e0       	ldi	r24, 0x05	; 5
 16c:	90 e0       	ldi	r25, 0x00	; 0
 16e:	86 df       	rcall	.-244    	; 0x7c
	  for(j=200;j>0;j--)
 170:	c8 ec       	ldi	r28, 0xC8	; 200
 172:	d0 e0       	ldi	r29, 0x00	; 0
		{
		BEEP_ON;delay_us(600);
 174:	92 98       	cbi	0x12, 2	; 18
 176:	88 e5       	ldi	r24, 0x58	; 88
 178:	92 e0       	ldi	r25, 0x02	; 2
 17a:	80 df       	rcall	.-256    	; 0x7c
		BEEP_OFF;delay_us(40);//1.25KHz
 17c:	92 9a       	sbi	0x12, 2	; 18
 17e:	88 e2       	ldi	r24, 0x28	; 40
 180:	90 e0       	ldi	r25, 0x00	; 0
 182:	7c df       	rcall	.-264    	; 0x7c
 184:	21 97       	sbiw	r28, 0x01	; 1
 186:	b1 f7       	brne	.-20     	; 0x174
 188:	df 91       	pop	r29
 18a:	cf 91       	pop	r28
 18c:	08 95       	ret

0000018e <__vector_7>:
 18e:	1f 92       	push	r1
 190:	0f 92       	push	r0
 192:	0f b6       	in	r0, 0x3f	; 63
 194:	0f 92       	push	r0
 196:	11 24       	eor	r1, r1
 198:	8f 93       	push	r24
 19a:	86 e0       	ldi	r24, 0x06	; 6
 19c:	82 bf       	out	0x32, r24	; 50
 19e:	80 91 8b 00 	lds	r24, 0x008B
 1a2:	8f 5f       	subi	r24, 0xFF	; 255
 1a4:	80 93 8b 00 	sts	0x008B, r24
 1a8:	8d 37       	cpi	r24, 0x7D	; 125
 1aa:	09 f5       	brne	.+66     	; 0x1ee
 1ac:	10 92 8b 00 	sts	0x008B, r1
 1b0:	80 91 8a 00 	lds	r24, 0x008A
 1b4:	8f 5f       	subi	r24, 0xFF	; 255
 1b6:	80 93 8a 00 	sts	0x008A, r24
 1ba:	8c 33       	cpi	r24, 0x3C	; 60
 1bc:	39 f4       	brne	.+14     	; 0x1cc
 1be:	10 92 8a 00 	sts	0x008A, r1
 1c2:	80 91 89 00 	lds	r24, 0x0089
 1c6:	8f 5f       	subi	r24, 0xFF	; 255
 1c8:	80 93 89 00 	sts	0x0089, r24
 1cc:	80 91 89 00 	lds	r24, 0x0089
 1d0:	8c 33       	cpi	r24, 0x3C	; 60
 1d2:	39 f4       	brne	.+14     	; 0x1e2
 1d4:	10 92 89 00 	sts	0x0089, r1
 1d8:	80 91 88 00 	lds	r24, 0x0088
 1dc:	8f 5f       	subi	r24, 0xFF	; 255
 1de:	80 93 88 00 	sts	0x0088, r24
 1e2:	80 91 88 00 	lds	r24, 0x0088
 1e6:	88 31       	cpi	r24, 0x18	; 24
 1e8:	11 f4       	brne	.+4      	; 0x1ee
 1ea:	10 92 88 00 	sts	0x0088, r1
 1ee:	8f 91       	pop	r24
 1f0:	0f 90       	pop	r0
 1f2:	0f be       	out	0x3f, r0	; 63
 1f4:	0f 90       	pop	r0
 1f6:	1f 90       	pop	r1
 1f8:	18 95       	reti

000001fa <LCD_en_write>:
		}
}


/*---------------LCD初始化----------------*/
void LCD_init(void) 
  { 
	delay_ms(50);                 //*************  
    LCD_write_char(0x30,0); 
    delay_ms(6); 
    LCD_write_char(0x30,0);       //这段加上去,不用阿莫介绍延时的那种 
    delay_ms(1); 
    LCD_write_char(0x30,0);        
    delay_ms(1); 
     LCD_write_char(0x02,0);                 //*******************/ 
    delay_ms(1); 
	
	
    LCD_write_char(0x28,0); //4bit test       显示模式设置(不检测忙信号) 
    delay_ms(1);  
    LCD_write_char( 0x08, 0);         // 显示关闭 
    delay_ms(1); 
    LCD_write_char( 0x01, 0);         // 显示清屏 
    delay_ms(1); 
    LCD_write_char( 0x06, 0);         // 显示光标移动设置 
    delay_ms(1); 
    LCD_write_char( 0x0C, 0);         // 显示开及光标设置 
    delay_ms(10); 



	
  } 


/*---------------写入使能---------------*/
void LCD_en_write(void)        //EN端产生一个高电平脉冲,写LCD 
  { 
    LCD_EN_PORT |= LCD_EN; 
 1fa:	af 9a       	sbi	0x15, 7	; 21
    delay_us(20); 
 1fc:	84 e1       	ldi	r24, 0x14	; 20
 1fe:	90 e0       	ldi	r25, 0x00	; 0
 200:	3d df       	rcall	.-390    	; 0x7c
		
    LCD_EN_PORT &= ~LCD_EN; 
 202:	af 98       	cbi	0x15, 7	; 21
	delay_us(20);
 204:	84 e1       	ldi	r24, 0x14	; 20
 206:	90 e0       	ldi	r25, 0x00	; 0
 208:	39 df       	rcall	.-398    	; 0x7c
 20a:	08 95       	ret

0000020c <LCD_wait_Ready>:
  } 


/*----------------------------------------------------------------------- 
LCD_write_char    : 英文字符串显示函数 

输入参数:*s      :英文字符串指针; 
          X、Y    : 显示字符串的位置,X:0-15,Y:0-1 
                    LCD第一行显示寄存器地址:0X80-0X8F 
                    LCD第一行显示寄存器地址:0XC0-0XCF 

编写日期          :2005-10-7  
最后修改日期      :        
-----------------------------------------------------------------------*/ 
void LCD_write_char(unsigned command,unsigned data) 
    { 
		unsigned command_temp,data_temp;         
		
		command_temp = command; 
		data_temp = data; 
		 
		LCD_wait_Ready(); 
	  
		LCD_RW_PORT &= ~LCD_RW;                 //RW=0 
		LCD_DATA_PORT &= 0X0f; 
		if (command == 0) 
		{ 
		   LCD_RS_PORT |= LCD_RS;             //RS=1  
		   LCD_DATA_PORT |= data_temp&0xf0;   //send high 4bit 
		} 
		else  
		{ 
		   LCD_RS_PORT &= ~LCD_RS;            //RS=0 
		   LCD_DATA_PORT |= command_temp&0xf0;//send high 4bit 
		} 
		LCD_en_write(); 
		
		LCD_DATA_PORT &= 0X0f; 
		command_temp=command_temp << 4;         //send low 4bit 
		data_temp=data_temp << 4; 
	  
		if (command==0) 
			LCD_DATA_PORT |= data_temp&0xf0; 
		else 
			LCD_DATA_PORT |= command_temp&0xf0; 
			LCD_en_write(); 
	
		LCD_RW_PORT |= LCD_RW; 
		LCD_RS_PORT ^= LCD_RS;     
    } 

void LCD_wait_Ready(void)                  //等待LCD空闲 
    { 
		LCD_DATA_DDR &= ~0x80;                 //PD7 I/O口方向设置为输入   
 20c:	d7 98       	cbi	0x1a, 7	; 26
		LCD_RW_PORT |= LCD_RW;                 //RW=1 
 20e:	ae 9a       	sbi	0x15, 6	; 21
		LCD_RS_PORT &= ~LCD_RS;                //RS=0 
 210:	ad 98       	cbi	0x15, 5	; 21
		LCD_EN_PORT |= LCD_EN;                 //EN=1 
 212:	af 9a       	sbi	0x15, 7	; 21
		while (!( LCD_DATA_PIN&0x80 ) == 0);   //RW=1,读PD7,为0表示空闲; 
 214:	cf 99       	sbic	0x19, 7	; 25
 216:	fe cf       	rjmp	.-4      	; 0x214
		LCD_EN_PORT &= ~LCD_EN;                //EN=0 
 218:	af 98       	cbi	0x15, 7	; 21
		LCD_DATA_DDR |= 0xf0; 
 21a:	8a b3       	in	r24, 0x1a	; 26
 21c:	80 6f       	ori	r24, 0xF0	; 240
 21e:	8a bb       	out	0x1a, r24	; 26
 220:	08 95       	ret

⌨️ 快捷键说明

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