|
/*测试MPCM 收9位 中断方式 第9位为0 = PORTD=6闪灯,910=d4,911=d5 atmega8 1,9,1格式*/
/*用的是proteus仿真,结果是能区分第九位为0,1,以及点名是否匹配,问题是无论第九位是0还是1,都响应中断*/
#include <iom8v.h>
#include <macros.h>
static void io_init(void)
{
PORTB = 0x0;
DDRB = 0x0;
PORTC = 0x0;
DDRC = 0x7F;
PORTD = 0x0;
DDRD = 0xfa;
}
void usart_s(unsigned char baud)
{
UCSRB = 0x00; //disable while setting baud rate
UCSRA = 0x21;
UCSRC=0x86;
UBRRL = 0x19;//(unsigned int) (baud);//1M晶振,2400波特率
UBRRH = 0x00;//(unsigned int ) (baud>>8);
UCSRB=0x9c;
}
#pragma interrupt_handler usart_r:12
void usart_r(void)
{
unsigned char r,r1,r2;
unsigned int r3,name=0x44;
CLI();
r=UDR;
PORTC^=0x02;//pc.1为中断标志位
if (r2==1)
{
if (r==name)
{
PORTD=((PORTD&0x0F)|0xa0);
UCSRA &=(~(1<<MPCM));
UCSRB &=(~(1<<RXB8));
}
else PORTD=((PORTD&0x0F)|0x90);
}
else PORTD=((PORTD&0x0F)|0x40);
SEI();
}
void main(void)
{
unsigned char baud=25;//1M晶振,2400波特率
int k;
CLI();
io_init( );
usart_s(baud);
PORTD=0;
PORTC=0;
SEI();
for ( ; ; )
{
PORTC^=0x08;//pc.3为主程序标志位
for (k=1;k<0xefff;k++)
{
;
}
}
} |
阿莫论坛20周年了!感谢大家的支持与爱护!!
一只鸟敢站在脆弱的枝条上歇脚,它依仗的不是枝条不会断,而是自己有翅膀,会飞。
|