numled.c

来自「MEga8的多通道AD转换演示程序」· C语言 代码 · 共 46 行

C
46
字号
/*******************************************/
/*            广州天河双龙电子公司         */
/*            http://www.sl.com.cn         */
/*              数码LED驱动程序            */
/*            作者:ntzwq@wx88.net          */
/*                2002年5月11日            */
/*   目标MCU:MEGA8   晶振:内部RC(INT) 8MHZ */
/*******************************************/
#include<iom8v.h>
const unsigned char seg_table[16]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,
0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e};
unsigned char led_buff[4]={0,0,0,0};
/*				微秒级延时程序	  		*/
void delay_us(int time)
	 {     
  	  do
	  	{
		 time--;
		}	
  	  while (time>1);
	 }	  
/*	  		    毫秒级延时程序			*/	 
void delay_ms(unsigned int time)
	 {
	  while(time!=0)
	  	  {		
		   delay_us(1000);
		   time--;
		  }
	 }					
void display(void)
	 {
	  unsigned char i;
	  DDRB=0xff;
	  PORTB=0xff;
	  DDRD|=0xf0;
	  PORTD|=0xf0;
	  for(i=0;i<4;i++)
	  	 {		  
		  PORTB=led_buff[i];
		  PORTD&=~(1<<(i+4));
		  delay_ms(1);
		  PORTD|=0xf0;
		 }
	 }

⌨️ 快捷键说明

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