proteus 仿真时出现错误:Invalid opcode 0xFFFF at PC=0x004E,图片如下
求高手解答,先谢谢了
具体程序如下:
//ICC-AVR applica
tion builder : 2012/7/24 11:03:31
// Target : M16
// Crystal: 8.0000Mhz
#include <iom16v.h>
#include <macros.h>
#define uchar unsigned char
#define uint unsigned int
#define ulong unsigned long
flash uchar tab[]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8, //共阳极0~F的段码
0x80,0x90,0x88,0x83,0xC6,0xA1,0x86,0x8E};
uchar cnt;
uint adc_v;
void delay(uint k) //延时约0.1ms
{
uchar m,n;
for(m=0;m<k;m++)
{
for(n=0;n<114;n++)
{;}
}
}
#pragma interrupt_handler timer1_compa_isr:7 //T/C0比较匹配中断服务
void timer1_compa_isr(void)
{
cnt=0x01;
}
#pragma interrupt_handler adc_isr:15 //ADC转换完成中断服务
void adc_isr(void)
{
uint adc_data;
adc_data=ADCH; //读取ADC转换结果
adc_v=(ulong)adc_data*5000/1024; //换算成电压值
}
void display(void)
{
uchar val1,val2,val3,val4;
val1=adc_v/1000;
val2=(adc_v/100)%10;
val3=(adc_v/10)%10;
val4=adc_v%10;
PORTD=0x01;
PORTC=tab[val1];
PORTC&=~BIT(PC7);
delay(10);
PORTD=0x02;
PORTC=tab[val2];
delay(10);
PORTD=0x03;
PORTC=tab[val3];
delay(10);
PORTD=0x08;
PORTC=tab[val4];
delay(10);
}
void main(void)
{
DDRA=0x00; //模拟量由PA0输入
PORTA=0x00;
DDRC=0xFF;
PORTC=0xFF; //PORTC端口与LED段码相连
DDRD=0xFF;
PORTD=0xFF;
TCCR0=0x0B; //内部时钟,64分频(8M/64=125Hz)
TCNT0=0x00;
OCR0=0xF9; //OCRO=0xF9(即249)
TIMSK=0x02; //允许T/C0比较中断
ADMUX=0x40; //参考
电源AVcc、ADC0单端输入
SFIOR&=0x1F;
SFIOR|=0x60; //选择T/C0比较匹配中断为ADC触发源
ADCSRA=0xAE;
SEI(); //开放全局中断
while(1)
{
if(cnt==0x01)
{
display(); //LED扫描显示
cnt=0x00;
}
}
一周热门 更多>