|
//檢測50Hz的主電
#include <iom88pv.h>
#include <macros.h>
#define uchar unsigned char
#define uint unsigned int
uchar i; //定義全局變量i
/***********************************************/
void port_init(void)
{
PORTC |= 0x10; //PC1引腳電平變化輸入端上拉高祖
DDRC |= 0x00;
PORTD |= 0x80; //PD7的LED輸出高電平
DDRD |= 0x80;
}
/**********************************************/
void uart0_init(void)
{
UCSR0B = 0x00;
UCSR0C = 0x06; //一個停止位,8個數(shù)據(jù)位
UBRR0L = 0x33; //波特率,9600
UBRR0H = 0x00;
UCSR0B = 0x18; //中斷使能
}
/*********************************/
void init_devices(void)
{
port_init();
uart0_init();
}
/**************************************/
void uart0_send(unsigned char i)
{
while(!(UCSR0A&(1<<UDRE0)));
UDR0=i;
}
/*************************************/
void main(void)
{
CLI();
init_devices();
PCICR |=0b00000010;
PCMSK1|=0b00010000;
SEI();
while(1)
{
if(i==50)
{
uart0_send(i);
i=0;
PORTD^=0x80;
}
}
}
/************************************/
#pragma interrupt_handler yinjiaov:5
void yinjiaov(void)
{
i++;
}
|
|