📄 001._c
字号:
//ICC-AVR application builder : 2005-9-7 11:07:15
// Target : M32
// Crystal: 7.3728Mhz
#include <iom32v.h>
#include <macros.h>
void port_init(void)
{
PORTA = 0x00;
DDRA = 0xFF;
PORTB = 0x00;
DDRB = 0xFF;
PORTC = 0x00;
DDRC = 0xFF;
PORTD = 0x00;
DDRD = 0xFF;
}
//Watchdog initialize
// prescale: 16K
void watchdog_init(void)
{
WDR(); //this prevents a timout on enabling
//WDTCR = 0x08; //WATCHDOG ENABLED - dont forget to issue WDRs
/* Write logical one to WDTOE and WDE */
WDTCR |= (1<<WDTOE) | (1<<WDE);
/* Turn off WDT */
WDTCR = 0x00;
}
//UART0 initialize
// desired baud rate: 9600
// actual: baud rate:9600 (0.0%)
// char size: 8 bit
// parity: Disabled
void uart0_init(void)
{
UCSRB = 0x00; //disable while setting baud rate
UCSRA = 0x00;
UCSRC = BIT(URSEL) | 0x06;
UBRRL = 0x2F; //set baud rate lo
UBRRH = 0x00; //set baud rate hi
UCSRB = 0x18;
}
void Delay1ms(void)
{
unsigned int i;
for(i=0;i<=(unsigned int)(7.3828*143-2);i++);
}
void Delayxms(unsigned char ms)
{
unsigned char i;
for(i=0;i<=ms;i++)Delay1ms();
}
//call this routine to initialize all peripherals
void main(void)
{
//stop errant interrupts until set up
unsigned char i;
CLI(); //disable all interrupts
port_init();
//watchdog_init();
uart0_init();
//Latch_H;
//Latch_L;
MCUCR = 0x00;
GICR = 0x00;
TIMSK = 0x00; //timer interrupt sources
//SEI(); //re-enable interrupts
//all peripherals are now initialized
asm("sbi 0x12,3");
asm("cbi 0x12,3");
i=0;
//for(i=0;i<10;i++)
do{
//UDR=0X55;
//while((UCSRA&0X40));
//UCSRA&=0b10111111;
PORTA=i;
asm("sbi 0x12,3");
asm("cbi 0x12,3");
Delayxms(1000);
i++;
}while(1);
//while(1);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -