金牌会员
- 积分
- 2433
- 威望
- 321
- 贡献
- 1864
- 兑换币
- 0
- 注册时间
- 2009-2-18
- 在线时间
- 124 小时
|
请高手给俺指正哪里不对啊 ?? 大家共同提高
#include <hidef.h>
#include <MC9S12xs128.h>
#pragma LINK_INFO DERIVATIVE "mc9s12xs128"
#define SAMP_ROW_SEP 3
#define SAMP_ROW_START 48
#define SAMP_ROW_MAX 248
#define SAMP_COL_SEP 1
#define SAMP_COL_START 16
#define SAMP_COL_MAX 41
#define IMAGE_ROW ((SAMP_ROW_MAX-SAMP_ROW_START)/SAMP_ROW_SEP)
#define IMAGE_COLUMN ((SAMP_COL_MAX-SAMP_COL_START)/SAMP_COL_SEP)
#define ROW_MIN 1
#define ROW_MAX IMAGE_ROW
#define COLUMN_MIN 1
#define COLUMN_MAX IMAGE_COLUMN
unsigned int ui_SampleRow=0,ui_SampleColumn=0;
unsigned char ucTemp;
unsigned char *pucTemp;
unsigned char text;
unsigned char uca_Buffer1[IMAGE_ROW][IMAGE_COLUMN];
unsigned char uca_Buffer2[IMAGE_ROW][IMAGE_COLUMN];
unsigned char *puca_BufferSample=&uca_Buffer1[0][0];
unsigned char *puca_BufferProcess=&uca_Buffer2[0][0];
unsigned char *puca_BufferTemp=&uca_Buffer1[0][0];
unsigned char chang;
unsigned char video_flag;
void SetBusCLK_40M(void);
void Init_SCI(void) ;
void AD_Init(void);
void SCI_TXD(unsigned char text);
void send(void);
void Init_tim(void);
void ISR_VsInit(void) ; // 场中断初始化
void interrupt ISR_Vs(void); //场中断处理程序
void ISR_VsDis(void) ; //场中断禁止
void ISR_HsInit(void); //行中断初始化
void interrupt ISR_Hs(void); //行中断处理程序
void ISR_HsDis(void) ; //行中断禁止
void main(void)
{ EnableInterrupts;
SetBusCLK_40M();
AD_Init();
ISR_VsInit();
Init_SCI();
while((chang==2)&&(video_flag==1))//采集了两场并且第二场采集完成
{
send();
chang=0;
video_flag=0;
}
}
/******************总线时钟***************************/
void SetBusCLK_40M(void)
{
CLKSEL=0X00;
PLLCTL_PLLON=1;
SYNR =0xc0 | 0x04;
REFDV=0x80 | 0x01;
POSTDIV=0x00;
_asm(nop);
_asm(nop);
while(!(CRGFLG_LOCK==1));
CLKSEL_PLLSEL =1;
}
/******************定时器初始化***************************/
void Init_tim(void)
{
TSCR1=0x80;
TSCR2=0X85;
TFLG2_TOF=1;
}
/******************AD初始化***************************/
void AD_Init(void)
{ ATD0CTL1=0x00;
ATD0CTL2=0x40;
ATD0CTL3=0x88;
ATD0CTL4=0x00;
ATD0CTL5=0x21;
ATD0DIEN=0x00;
}
/******************串口初始化*************************/
void Init_SCI(void)
{
SCI0CR1 =0x00;
SCI0CR2 =0x2c;
SCI0BDH =0x01;
SCI0BDL =0x04;
}
/******************串口发送函数***********************/
void SCI_TXD(unsigned char text)
{
unsigned char temp;
temp=SCI0SR1;
while (!(SCI0SR1&0x80));
SCI0DRH=0;
SCI0DRL=text;
}
void send(void)
{
int a,b;
unsigned char data;
unsigned char *DataAddress;
SCI_TXD(0);
for(a=1;a<ROW_MAX;a++)
{
for(b=1;b<COLUMN_MAX;b++)
{
DataAddress=puca_BufferProcess+IMAGE_COLUMN*a+b;
data=*DataAddress;
SCI_TXD(data);
}
SCI_TXD(0);
}
SCI_TXD(0);
}
/******************场同步初始化***************************/
void ISR_VsInit(void)
{ TSCR1=0X80;// 定时器模块控制寄存器 0B10000000定时器使能
TSCR2=0X85; //定时器模块控制寄存器 0B00000101预分频系数为32
TFLG2_TOF=1;
TIE_C3I=1; //3通道输入捕捉中断使能
TIOS_IOS3=0; //3通道设置为输入捕捉
TCTL2_OM3=0; //
TCTL2_OL3=0; //定时器与输出引脚断开
TCTL4_EDG3B=1; //
TCTL4_EDG3A=0; //下降沿捕捉 有待考虑之处
TFLG1_C3F=1; //清除通道3的中断标志位 允许通道3中断
chang=0;
}
/******************场中断禁止***************************/
void ISR_VsDis(void)
{ TIE_C3I=0; //3通道输入捕捉中断禁止
}
/******************行同步初始化***************************/
void ISR_HsInit(void)
{TSCR1=0X80; // 定时器模块控制寄存器 0B10000000定时器使能
TSCR2=0X85; //定时器模块控制寄存器 0B00000101预分频系数为32
TFLG2_TOF=1;
TIOS_IOS4=0; //4通道设置为输入捕捉
TIE_C4I=1; // 4通道输入捕捉中断使能
TCTL1_OM4=0; //
TCTL1_OL4=0; //定时器与输出引脚断开 有待考虑之处
TCTL3_EDG4B=1;//
TCTL3_EDG4A=0; // 下降沿捕捉
TFLG1_C4F=1; //清除通道4的中断标志位 允许行同步中断
}
/******************行中断禁止***************************/
void ISR_HsDis(void)
{ TIE_C4I=0;//行中断禁止
}
#pragma CODE_SEG __NEAR_SEG NON_BANKED
/******************场中断服务处理函数***************************/
void interrupt 11 ISR_Vs(void) // t3
{ TFLG1_C3F=1 ; //清除通道3的中断标志位 允许场同步中断
ISR_VsDis();//场中断禁止
ISR_HsInit(); //行中断初始化
chang++;
ui_SampleRow=0;
ui_SampleColumn=0;
}
/******************行同步处理函数***************************/
void interrupt 12 ISR_Hs(void) //t4
{
TFLG1_C4F=1;
ui_SampleRow++;
if(ui_SampleRow>=SAMP_ROW_START&&ui_SampleRow<SAMP_ROW_MAX)
{
if(ui_SampleRow%SAMP_ROW_SEP==0)
{
for(ui_SampleColumn=0;ui_SampleColumn<SAMP_COL_MAX;ui_SampleColumn++)
{
while(!ATD0STAT0_SCF);
if(ui_SampleColumn>=SAMP_COL_START)
{ pucTemp=puca_BufferSample+((ui_SampleRow-SAMP_ROW_START)/SAMP_ROW_SEP)*IMAGE_COLUMN+(ui_SampleColumn-SAMP_COL_START);
*pucTemp=ATD0DR0L;
ucTemp=ATD0DR0L;
}
}
}
}
if(ui_SampleRow>SAMP_ROW_MAX)
{ ISR_HsDis();//关闭行中断
video_flag=1; //标志一场采集完成
}
} |
|