智能车制作

标题: ccd 图像采集的问题 [打印本页]

作者: 黑色007    时间: 2010-1-19 02:52
标题: ccd 图像采集的问题
哪位高手帮我看看这个程序才出来的图像很暗啊?我搞了好久,不知道哪里出问题了,,帮帮忙啊,程序如下:
#include <hidef.h>      /* common defines and macros */
#include <MC9S12XS128.h>     /* derivative information */
#pragma LINK_INFO DERIVATIVE "mc9s12xs128"
#define HIGH 70
#define WIDTH 37           //最大每行可采48点

#define SAMP_ROW_SEP 4      //行采样间隔
#define SAMP_ROW_START 28   //采样起始行
#define SAMP_ROW_MAX 308    //采样最大行
unsigned char SAMP_ROW_CUR=0;   //采样当前行
unsigned char SAMP_COL_CUR=0;   //采样当前列
unsigned char row=0;
   
unsigned char a[HIGH][WIDTH];

void SetBusCLK_48M(void)
{   
    CLKSEL=0X00;    //disengage PLL to system
    PLLCTL_PLLON=1;   //turn on PLL
    SYNR =0xc0 | 0x05;                        
    REFDV=0x80 | 0x01;
    POSTDIV=0x00;       //pllclock=2*osc*(1+SYNR)/(1+REFDV)=96MHz;
    _asm(nop);          //BUS CLOCK=48M
    _asm(nop);
    while(!(CRGFLG_LOCK==1));   //when pll is steady ,then use it;
    CLKSEL_PLLSEL =1;          //engage PLL to system;
}
void vADInit(void)
{
    ATD0CTL1=0b00000000;//8位精度
    ATD0CTL2=0b01000000;//禁止外部触发,标志位快速清零,中断禁止
    ATD0CTL3=0b10001000;//右对齐无符号.转换序列长度为1,No FIFO模式,Freeze模式下继续转换?
    ATD0CTL4=0b00000001;//4AD采样周期,ATDClock=[BusClock*0.5]/[PRS+1]  ; PRS=15, divider=32
    ATD0CTL5=0b00100000;//特殊通道禁止,单通道采样,扫描模式连续采样,ch AN0
    ATD0DIEN=0b00000000;//禁止数字输入
}
/***************************行场中断初始化************************************/
void vinterruptsinit(void)
{
    TSCR1=0x80;//TIMER 定时器使能
    TIE  =0x00;//禁止中断
    TCTL3=0x00;//EDGnB EDGnA 1表示上升沿, 2表示下降沿, 3表示任何沿      
    TCTL4=0x05;//通道0上升沿触发,通道1上升沿触发
    TIOS =0x00;//每一位对应通道的: 0输入捕捉,1输出比较
   // TIE_C0I=1;//中断使能
    TIE_C1I=1;//中断使能
}
static void sci_init(void)
{
SCI0CR2 = 0x2c; //enable Receive Full Interrupt,RX enable,Tx enable
SCI0BDH = 0x01; //busclk  8MHz,19200bps,SCI0BDL=0x1a
SCI0BDL = 0x38; //SCI0BDL=busclk/(16*目标波特率)
}
/******************************通信***************************/
// 向串口发送一个字符
void uart_putchar(unsigned char ch)
{
if (ch == '\n')
{
  while (!(SCI0SR1&0x80)) ;
  SCI0DRL = 0x0d;            //output'CR'
  return ;
}
while (!(SCI0SR1&0x80)) ;       //keep waiting when not empty
SCI0DRL = ch;
}
// 发送字符串
void putstr( unsigned char ch[])
{
unsigned char ptr = 0;
while (ch[ptr])
{
  uart_putchar((unsigned char)ch[ptr++]);
}
}
// 向电脑主机发送一副图像信息
void putimg()
{
unsigned char xc1[] = "<img>";
unsigned char xc2[] = "<line>";
unsigned char xc3[] = "</line>";
unsigned char xc4[] = "</img>";
unsigned int ptr = 0;
unsigned int i, j;
unsigned char im;
putstr(xc1);
for (i = 0; i < HIGH; i++)
{
  putstr(xc2);
  for (j = 0; j < WIDTH;j++)
  {
    im = a[i][j];
   uart_putchar((unsigned char) im);
  }
  putstr(xc3);
}
putstr(xc4);
}


void main(void)
{
  DisableInterrupts;
  SetBusCLK_48M();
  vADInit();
  sci_init();
  vinterruptsinit();
  EnableInterrupts;
  DDRB=0XFF;
  while(1)
  {  
    ;        
  }
}

#pragma CODE_SEG __NEAR_SEG NON_BANKED
void interrupt 8 Port0_interrupt(void)   //行中断
{
  int i;
  TFLG1_C0F=1;       //清除行中断标志
   
  for(i=0;i<25;i++)//行效应
  {
   asm(nop);
  }
  if(SAMP_ROW_CUR>=SAMP_ROW_START&&SAMP_ROW_CUR<SAMP_ROW_MAX) {
  
    if((SAMP_ROW_MAX-SAMP_ROW_START)%SAMP_ROW_SEP==0) {
      
      for(i=0;i<WIDTH;i++) {
        while(ATD0STAT0_SCF==0);
        a[row][i]=ATD0DR0L;
      }
      row++;
    }
  }
  SAMP_ROW_CUR++;
}


void interrupt 9 Port1_interrupt(void)
{
    TIE_C0I=0;//禁止行中断
    TFLG1_C1F=1;
   
//   delayms(1);
    SAMP_ROW_CUR=0;//采样行归零   

    TIE_C0I=1;//行中断使能
    PORTB=0x0f;
    putimg();
   // PORTB=0xf0;
}   
#pragma CODE_SEG DEFAULT
作者: 261069267    时间: 2010-1-22 17:00
模拟摄像头?是不是AD充电时间不够
作者: 时代还怪    时间: 2010-4-12 14:50
外部电路问题或是光线不足问题吧!
作者: kpkplp    时间: 2011-10-20 15:30
哈哈 没事看看阿
作者: kpkplp    时间: 2011-10-20 15:38
哈哈 没事看看阿




欢迎光临 智能车制作 (http://dns.znczz.com/) Powered by Discuz! X3.2