智能车制作
标题:
高人帮我看看,哪里出错了?
[打印本页]
作者:
I08690127
时间:
2011-3-7 14:18
标题:
高人帮我看看,哪里出错了?
主要问题是AD采集那里
在AD中要是不用if else语句给data赋值,而就是用data[y][x]=(uchar)ATD0DR0;时正常,但是好像就是因为给data[y][x]赋值两次就
出现问题了,要是用固定的data[?][?] 是正常的。不懂为什么
是data[][]这种二维数组访问时间很长还是怎么的?感觉就是很莫名其妙....代码附上....
#include <hidef.h> /* common defines and macros */
#include "derivative.h" /* derivative-specific definitions */
#include "init.h"
#define XMAX 32
#define YMAX 70
volatile uint rticnt = 0;
volatile uchar adstart = 0;
uchar data[YMAX][XMAX];
volatile uchar x = 0,y = 0;
volatile temp;
void main(void) {
/* put your own code here */
DisableInterrupts;
DDRB = 0xff;
PLL_init(); // 40M
PIT_init(); // 中断未开启 PITINTE 开启前清零
IRQ_init(); // 下降沿中断
AD_init(); // 中断开启
RTI_init();
ECT_init();
EnableInterrupts;
for(;;) {
if(rticnt>=100)
{
PORTB_PB6 = !PORTB_PB6;
PORTB_PB7 = !PORTB_PB7;
rticnt = 0;
}
_FEED_COP(); /* feeds the dog */
} /* loop forever */
/* please make sure that you never leave main */
}
#pragma CODE_SEG NON_BANKED
void interrupt 7 RTI_ISR(void)
{
CRGFLG_RTIF = 1;
rticnt++;
}
void interrupt 6 IRQ_ISR(void)
{
PITCFLMT_PFLMT0 = 1; // 强制读取MT0
PITFLT_PFLT0 = 1; // PIT0强制读取
PITTF = 0xff; // 标志位清0
PITINTE = 0x01; // 中断使能
x = 0;
y = 0;
}
void interrupt 10 T2_ISR(void) // 中断换行
{
TFLG1_C2F = 1;
y++; // 换行
x = 0; // 清零
PORTB_PB2 = !PORTB_PB2;
}
void interrupt 22 AD_ISR(void)
{
DisableInterrupts;
ATD0STAT0_SCF = 1; // 标志位清零
if(adstart)
{
if(x<XMAX&&y<YMAX)
{
if(ATD0DR0>0x85)
{
data[y][x] = '.';
}
else
{
data[y][x] = 'a'; //
在AD中要是不用if else语句给data赋值,而就是用data[y][x]=(uchar)ATD0DR0;时正常
}
}
x++;
PORTB_PB1 = !PORTB_PB1; // 开始记录AD数据
}
EnableInterrupts;
}
void interrupt 66 PIT0_ISR(void) // 1.45ms
{
PITCFLMT_PFLMT0 = 1; // 强制读取MT0
PITFLT_PFLT1 = 1; // PIT1强制读取
PITTF = 0xff; // 标志位清0
PITINTE = 0x02; // 中断使能
TIE = 0x04; // 行中断允许
adstart = 1;
PORTB_PB0 = 1;
}
void interrupt 67 PIT1_ISR(void) // 18.0ms
{
PITTF_PTF1 = 1;
PITINTE = 0x00; // 关中断
TIE = 0x00; // 行中断关闭
adstart = 0;
PORTB_PB0 = 0;
}
欢迎光临 智能车制作 (http://111.231.132.190/)
Powered by Discuz! X3.2