金牌会员
- 积分
- 1143
- 威望
- 268
- 贡献
- 827
- 兑换币
- 0
- 注册时间
- 2009-3-6
- 在线时间
- 24 小时
|
#include <hidef.h> /* common defines and macros */
#include <MC9S12XS128.h> /* derivative information */
#pragma LINK_INFO DERIVATIVE "mc9s12xs128"
#define ROW_END 270 //最后采集的一行
#define ROW_START 45 //最先采集的一行
#define Row 46 //采集的图像行数
#define Line 46 //采集的图像列数
unsigned char row; //行变量
unsigned char line; //列变量
unsigned int rowcount; //行计数器
unsigned char video[Row][Line]; //采集的图像信息
void init_PLL(void) //CPU总线时钟60M
{
SYNR=0xce;
REFDV=0x43;
POSTDIV=0x00; //bus period=16Mhz*(SYNDIV+1)/(REFDIV+1)=60M
while(0==CRGFLG_LOCK); //wait for VCO to stablize
CLKSEL=0x80; //open PLL
}
void init_PORT(void) //端口初始化
{
DDRT_DDRT0=0; //PT0作为奇偶场信号输入
IRQCR_IRQE =1; //下降沿触发
IRQCR_IRQEN=0; //禁止外部IRQ使能
}
void init_AD(void)
{
ATD0CTL1=0x00; //External trigge source is AN0,
//8-bit data,No discharge before sampling
ATD0CTL2=0x60; //quick clear CCFx,
//contine to transform under wait mode,
//Disable external trigger,
//ATD Sequence Complete interrupt requests are disabled,
//ATD Compare interrupt requests are disabled
ATD0CTL3=0x88; //one transform in one sequence,
//No FIFO,Right justied,
//contine to transform under freeze mode
ATD0CTL4=0x01; //four clocks,ATDCLK=[BusClock*0.5]/[PRS+1]=15M
ATD0CTL5=0x20; //Continuous Conversion Sequence Mode,
//Analog Input Channel is AN0
ATD0DIEN=0x00; //inhibit digital input
}
void init_SCI(void)
{
SCI0BDL=0x86; //9600bps
SCI0BDH=0x01;
SCI0CR1=0x00; //正常8位模式,无奇偶校验
SCI0CR2=0x0c; //允许查询方式收发
}
void SCI_Transmit(unsigned char ch) //发送函数
{
//等待发送缓冲区空
while (!(SCI0SR1&0x80));
SCI0DRL=ch;
}
void image_change(void)
{
char m;
char n;
for(m=0;m<Row;m++)
{
for(n=0;n<Line;n++)
{
if(video[m][n]>235) video[m][n]=235;
SCI_Transmit(video[m][n]);
}
}
}
void main(void)
{
init_PLL();
init_PORT();
EnableInterrupts;
for(;;)
{
if(PTIT_PTIT0==1)
{
while(PTIT_PTIT0==1);
row=0;
rowcount=0;
IRQCR_IRQEN=1;
while(rowcount<=ROW_END)
{}
IRQCR_IRQEN=0;
image_change();
}
else
{
while(PTIT_PTIT0==0);
row=0;
rowcount=0;
IRQCR_IRQEN=1;
while(rowcount<=ROW_END)
{}
IRQCR_IRQEN=0;
image_change();
}
}
}
#pragma CODE_SEG __NEAR_SEG NON_BANKED
void interrupt 6 IRQ_ISR()
{
rowcount++;
if((rowcount>=ROW_START)&&(rowcount%5==0)&&(row<Row))
{
init_AD();
for(line=0;line<Line;line++)
{
while(!ATD0STAT2_CCF0);
video[row][line]= ATD0DR0L;
//SCI_Transmit(video[row][line]);
}
row++;
ATD0CTL2=0x00; //清除AD缓存的数据,等待下一行的到来
}
} |
|