智能车制作

 找回密码
 注册

扫一扫,访问微社区

查看: 1301|回复: 0
打印 上一主题 下一主题

高人帮我看看,哪里出错了?

[复制链接]

4

主题

33

帖子

0

精华

中级会员

Rank: 3Rank: 3

积分
400
威望
265
贡献
45
兑换币
2
注册时间
2011-1-18
在线时间
45 小时
跳转到指定楼层
1#
发表于 2011-3-7 14:18:59 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
主要问题是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;  
}
您需要登录后才可以回帖 登录 | 注册

本版积分规则

关于我们|联系我们|小黑屋|智能车制作 ( 黑ICP备2022002344号

GMT+8, 2024-9-24 15:25 , Processed in 0.080524 second(s), 30 queries , Gzip On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表