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

📄 bei20061217 led.c

📁 51单片机的
💻 C
字号:
//ICC-AVR application builder : 2006-12-16 0:17:05
// Target : M16
// Crystal: 16.000Mhz //注册大小写识别   开始必须为字母

#include <iom16v.h>
#include <macros.h>
#include "led.h"
#define uchar unsigned char
uchar LED_DATA[11]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0Xa1}; //11 FOR "d"
uchar JS_001=0;
// 共阳极用 
void port_init(void)
{
 PORTA = 0xFF;
 DDRA  = 0xFF;
 PORTB = 0x0F;
 DDRB  = 0x0F;
 PORTC = 0x1F; //m103 output only
 DDRC  = 0x10;
 PORTD = 0x00;
 DDRD  = 0x00;
}

//Watchdog initialize
// prescale: 16K 
void watchdog_init(void)
{
 WDR(); //this prevents a timout on enabling
 WDTCR = 0x08; //WATCHDOG ENABLED - dont forget to issue WDRs
}

#pragma interrupt_handler eeprom_ready_isr:16
void eeprom_ready_isr(void)
{
 //eeprom ready event
}
/*
//TIMER0 initialize - prescale:64
// WGM: Normal
// desired value: 1mSec
// actual value:  1.000mSec (0.0%)
void timer0_init(void)
{
 TCCR0 = 0x00; //stop
 TCNT0 = 0x06; //set count
 OCR0  = 0xFA;  //set compare
 TCCR0 = 0x03; //start timer
 }
 */
//TIMER0 initialize - prescale:8
// WGM: Normal
// desired value: 100uSec
// actual value: 100.000uSec (0.0%)
void timer0_init(void)
{
 TCCR0 = 0x00; //stop
 TCNT0 = 0xCE; //set count
 OCR0  = 0x32;  //set compare
 TCCR0 = 0x02; //start timer
}

#pragma interrupt_handler timer0_ovf_isr:10
void timer0_ovf_isr(void)
{
 TCNT0 = 0xCE; //reload counter value
/*}

#pragma interrupt_handler timer0_ovf_isr:10
void timer0_ovf_isr(void)
{
 TCNT0 = 0x06; //reload counter value*/
 LED_SCAN(); 
}
void LED_SCAN()
{
   JS_001=++JS_001;
if (JS_001<=10)
   {
   HC573_CLK_PORTC|=HC573_CLK;     // PC4 =1
   LED_SCAN_PORTB|=0xff;
   LED_SCAN_PORTB&=~LED_V1;       //PB0=0
   LED_DATA_PORTA&=0X00;          //OUT LED_DATA
   LED_DATA_PORTA|=LED_DATA[10];
   if (JS_001>=3)
       HC573_CLK_PORTC&=~HC573_CLK;     // PC4 =0
   else 
       HC573_CLK_PORTC|=HC573_CLK;     // PC4 =1
   }
else if (JS_001>10,JS_001<=20)
   {
   HC573_CLK_PORTC|=HC573_CLK;     // PC4 =0
   LED_SCAN_PORTB|=0xff;
   LED_SCAN_PORTB&=~LED_V2;       //PB1=0
   LED_DATA_PORTA&=0X00;
   LED_DATA_PORTA|=LED_DATA[0];
   if (JS_001>=13)
       HC573_CLK_PORTC&=~HC573_CLK;     // PC4 =0
   else 
       HC573_CLK_PORTC|=HC573_CLK;     // PC4 =1
   }
else if (JS_001>20,JS_001<=30)
   {
   HC573_CLK_PORTC|=HC573_CLK;     // PC4 =1
   LED_SCAN_PORTB=0xff;
   LED_DATA_PORTA&=0X00;
   LED_DATA_PORTA|=LED_DATA[0];
   LED_SCAN_PORTB&=~LED_V3;       //PB2=0
   if (JS_001>=23)
       HC573_CLK_PORTC&=~HC573_CLK;     // PC4 =0
   else 
       HC573_CLK_PORTC|=HC573_CLK;     // PC4 =1
   }     
else
   {
   
   HC573_CLK_PORTC|=HC573_CLK;     // PC4 =1
   LED_SCAN_PORTB=0xff;
   LED_DATA_PORTA&=0X00;
   LED_DATA_PORTA|=LED_DATA[1];
    LED_SCAN_PORTB&=~LED_V4;       //PB3=0
   if (JS_001>=33)
       HC573_CLK_PORTC&=~HC573_CLK;     // PC4 =0
   else 
       HC573_CLK_PORTC|=HC573_CLK;     // PC4 =1
   if (JS_001==40)
       JS_001&=0; 
   }

}

//UART0 initialize
// desired baud rate: 250000
// actual: baud rate:250000 (0.0%)
// char size: 9 bit
// parity: Odd
void uart0_init(void)
{
 UCSRB = 0x00; //disable while setting baud rate
 UCSRA = 0x03;
 UCSRC = BIT(URSEL) | 0x36;
 UBRRL = 0x07; //set baud rate lo
 UBRRH = 0x00; //set baud rate hi
 UCSRB = 0xFC;
}


#pragma interrupt_handler uart0_rx_isr:12
void uart0_rx_isr(void)
{
 //uart has received a character in UDR
}

#pragma interrupt_handler uart0_udre_isr:13
void uart0_udre_isr(void)
{
 //character transferred to shift register so UDR is now empty
}

#pragma interrupt_handler uart0_tx_isr:14
void uart0_tx_isr(void)
{
 //character has been transmitted
}

//call this routine to initialize all peripherals
void init_devices(void)
{
 //stop errant interrupts until set up
 CLI(); //disable all interrupts
 port_init();
 watchdog_init();
 timer0_init();
 uart0_init();

 MCUCR = 0x00;
 GICR  = 0x00;
 TIMSK = 0x01; //timer interrupt sources
 SEI(); //re-enable interrupts
 //all peripherals are now initialized
}

//
void main(void)
{
 init_devices();
 //insert your functional code here...
}

⌨️ 快捷键说明

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