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

📄 led.c

📁 atmega8的关于LED的代码
💻 C
字号:
/*********************************************
************PC0==>DATA
************PC1==>SCLK
************PC2==>C0
************PC3==>C1
************PC4==>C2
************PC5==>C3
************PC6==>C4
**********************************************/
//ICC-AVR application builder : 2007-4-4 15:05:58
// Target : M8
// Crystal: 11.059Mhz

#include <iom8v.h>
#include <macros.h>

void port_init(void)
{
 PORTB = 0xFF;
 DDRB  = 0x00;
 PORTC = 0x7F; //m103 output only
 DDRC  = 0x7F;
 PORTD = 0xFF;
 DDRD  = 0x00;
}
/*****************************延时函数**************************************/
void delay_1ms(void)//1ms延时函数
{
 unsigned int i;
 for (i=1;i<1571;i++)
 ;
}
void delay_ms (unsigned int n)
{
 unsigned int i=0;
 for (i=0;i<n;i++)
 delay_1ms();
} 
/************************虚拟串行显示通道0***************************/
unsigned char VUART0 (unsigned char Display)
{
 unsigned char VBUF,bit_ctr,count1,count2;
  VBUF=Display;
  bit_ctr=0x01;
  for (count2=0;count2<8;count2++)
  {
  if ((VBUF&bit_ctr)==0x00)
   {//数据为0   
    PORTC=0b00111100;//PC0=RXD数据
	delay_ms (2);	    
	PORTC=0b00111110;//PC1=TXD时钟	
	delay_ms (2);
    PORTC=0b00111111;//PC1=TXD时钟
   }
  else
   {//数据为1
    PORTC=0b00111101;//PC0=RXD数据
	delay_ms (2);
    PORTC=0b00111111;//PC1=TXD时钟    
   }
   bit_ctr<<=1;
  }

}
//call this routine to initialise all peripherals
void init_devices(void)
{
 //stop errant interrupts until set up
 CLI(); //disable all interrupts
 port_init();

 MCUCR = 0x00;
 GICR  = 0x00;
 TIMSK = 0x00; //timer interrupt sources
 SEI(); //re-enable interrupts
 //all peripherals are now initialised
}
void main()
{
 init_devices(); 
 
 //while(1) 
 // {
    VUART0 (0xff);
  //}	
}

⌨️ 快捷键说明

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