写的熔丝位匹配程序,可以进入if判断语句,就是不往串口寄存器UDR0写入数据0x55,求高人解答,感激涕零!
#include
#include
#define F_CPU 12000000UL
#define baud 9600
int fuse_check();
void uart0_init(void);
void delay_1ms();
void main()
{
uart0_init();
if(fuse_check()==0)
{
while(1)
{
while( !(UCSR0A & (1<
UDR0 = 0x55; //发送数据0x55
//delay_1ms();
}
}
//else
// UDR0 = 0x66; //发送数据0x66
}
int fuse_check()
{
unsigned int a=0,b=1;
// 读取熔丝位低字节
asm("LDI R30,0x00"); //赋0x0000给Z指针
asm("LDI R31,0x00");
SPMCSR = 0x09; //置位SPMCSR寄存器
asm("LPM"); //读取低字节数据给R0
asm("STS 0x002E,R0"); //复制R0数据给PORTE
if(PORTE==0x0C) //低字节匹配判断
{
//读取熔丝位高字节
asm("LDI R30,0x03"); //赋0x0003给Z指针
asm("LDI R31,0x00");
SPMCSR=0x09; //置位SPMCSR寄存器
asm("LPM"); //读取低字节数据给R0
asm("STS 0x002E,R0"); //复制R0数据给PORTE
if(PORTE==0x00) //高字节匹配判断
{
//读取熔丝位扩展字节
asm("LDI R30,0x02"); //赋0x0002给Z指针
asm("LDI R31,0x00");
SPMCSR=0x09; //置位SPMCSR寄存器
asm("LPM"); //读取低字节数据给R0
asm("STS 0x002E,R0"); //复制R0数据给PORTE
if(PORTE==0x4A) //扩展字节匹配判断
{
b=0;
return b;
}
else
{
a=1;
return a;
}
}
else
{
a=1;
return a;
}
}
else
{
a=1;
return a;
}
}
//UART0初始化
void uart0_init(void)
{
UCSR0A = 0x00; //设置波特率时无效
UCSR0B = 0x00;
UCSR0C = 0x00;
UBRR0L =(F_CPU/baud/8-1)%256;
UBRR0H =(F_CPU/baud/8-1)/256;
UCSR0C = (1<
UCSR0B = (1<
}
暂无评论,赶紧抢沙发吧