高级会员
- 积分
- 943
- 威望
- 528
- 贡献
- 215
- 兑换币
- 61
- 注册时间
- 2012-2-26
- 在线时间
- 100 小时
|
采集不到数据,好像程序始终在场中断里死循环,跳不出去。在场中断处理函数interrupt 9 void VSYN_Interrupt(void)里面都写了TIE=OX02,强行关闭场中断了,可还是在场中断里执行,跳不进行中断处理函数interrupt 8 void HREF_Interrupt(void) 。因此采集不到数据,串口软件里始终显示的是0,我摄像头选的是ov7620。
路过的飘过的都来指导指导小弟吧,快纠结死了,万分感谢......
#include <hidef.h> /* common defines and macros */
#include "derivative.h" /* derivative-specific definitions */
#include <MC9S12G128.h>
#define ROW 30
#define COLUMN 70
unsigned char Image_Data[ROW][COLUMN];
unsigned char Point_C, VSYN_C=0, Line_Flag, m = 0,n=0;
unsigned int Line_C=0;
unsigned char Interval;
unsigned char THRESHOLD=0x20;
void Delay(int i)
{
int j;
for(j=0;j<i;j++)
{
_asm(nop);
}
}
void SetBusCLK_nM(byte nM)
{
MMCCTL1=0X00;
PKGCR =0X06;
DIRECT =0x00;
IVBR =0xFF;
ECLKCTL=0xC0;
CPMUPROT =0x26; //停止保护时钟配置寄存器
CPMUCLKS_PSTP=0; //
CPMUCLKS_PLLSEL=1; //应用PLL
//CPMUSYNR =nM-1; //设置分频因子
CPMUSYNR =0x40|(nM-1); //设置分频因子
CPMUREFDIV =0x80|0x00; //pllclock=2*(1+SYNR)= MHz;
CPMUPOSTDIV=0x00; // Set the post divider register
CPMUPOSTDIV=0x00; // Set the post divider register
CPMUPLL =0x10; // Set the PLL frequency modulation
while(CPMUFLG_LOCK == 0); /* Wait until the PLL is within the desired tolerance of the target frequency */
CPMUPROT=0x00; /* Enable protection of clock configuration registers */
}
void TIM_Init(void)
{
TIOS=0x00; //外部输入捕捉 1,2 通道
TCTL4=0x24; //通道1上升沿触发,通道 2 下降沿触发
TSCR1=0x80; //使能
TIE=0x06; //通道 1,2 中断使能
TFLG1=0xFF; //清中断标志位
}
void IO_init(void)
{ // IO初始化函数
DDRD = 0X00;
}
void SCI0_Init(void)
{
SCI0BD = 0X9C; //9600
SCI0CR1 = 0X00; /*normal,no parity*/
SCI0CR2 = 0X2C; //发送器,接收器使能
/*RIE=1,TE=1,RE=1, */
}
void SCI_Write(unsigned char SendChar)
{
while (!(SCI0SR1&0x80))
SCI0DRH=0;
SCI0DRL=SendChar;
}
//图像处理函数
void Process(void)
{
unsigned char i,j;
for(i=0;i<ROW;i++)
{
for(j=0;j<COLUMN;j++)
{
if(Image_Data[j]>THRESHOLD)
SCI_Write('1') ;
else SCI_Write('0') ;
}
//SCI_Write(0x0D);
//SCI_Write(0X0A);
}
}
//主函数
void main(void) {
/* put your own code here */
/* uchar x,data; */
DisableInterrupts;
SetBusCLK_nM(24);
TIM_Init();
IO_init() ;
SCI0_Init();
EnableInterrupts;
for(;;) {
Process() ;
_FEED_COP(); /* feeds the dog */
} /* loop forever */
/* please make sure that you never leave main */
}
//行中断处理函数
#pragma CODE_SEG NON_BANKED
interrupt 8 void HREF_Interrupt(void)
{
TFLG1_C1F = 1;
Line_Flag = 0;
m++; //每一个下降沿捕捉一次脉冲
if ( m<12 || m>288 )
{
return;//判断是否从新的一场开始
}
if(m<=144) Interval=12;
else if(m>144&&m<=200) Interval=8;
else if(m>200&&m<=252) Interval=6;
else Interval=4;
if(m%Interval==0)
{
Delay(1);
Image_Data[Line_C][0] = PORTD;Image_Data[Line_C][1] = PORTD;
Image_Data[Line_C][2] = PORTD;Image_Data[Line_C][3] = PORTD;
Image_Data[Line_C][4] = PORTD;Image_Data[Line_C][5] = PORTD;
Image_Data[Line_C][6] = PORTD;Image_Data[Line_C][7] = PORTD;
Image_Data[Line_C][8] = PORTD;Image_Data[Line_C][9] = PORTD;
Image_Data[Line_C][10] = PORTD;Image_Data[Line_C][11] = PORTD;
Image_Data[Line_C][12] = PORTD;Image_Data[Line_C][13] = PORTD;
Image_Data[Line_C][14] = PORTD;Image_Data[Line_C][15] = PORTD;
Image_Data[Line_C][16] = PORTD;Image_Data[Line_C][17] = PORTD;
Image_Data[Line_C][18] = PORTD;Image_Data[Line_C][19] = PORTD;
Image_Data[Line_C][20] = PORTD;Image_Data[Line_C][21] = PORTD;
Image_Data[Line_C][22] = PORTD;Image_Data[Line_C][23] = PORTD;
Image_Data[Line_C][24] = PORTD;Image_Data[Line_C][25] = PORTD;
Image_Data[Line_C][26] = PORTD;Image_Data[Line_C][27] = PORTD;
Image_Data[Line_C][28] = PORTD;Image_Data[Line_C][29] = PORTD;
Image_Data[Line_C][30] = PORTD;Image_Data[Line_C][31] = PORTD;
Image_Data[Line_C][32] = PORTD;Image_Data[Line_C][33] = PORTD;
Image_Data[Line_C][34] = PORTD;Image_Data[Line_C][35] = PORTD;
Image_Data[Line_C][36] = PORTD;Image_Data[Line_C][37] = PORTD;
Image_Data[Line_C][38] = PORTD;Image_Data[Line_C][39] = PORTD;
Image_Data[Line_C][40] = PORTD;Image_Data[Line_C][41] = PORTD;
Image_Data[Line_C][42] = PORTD;Image_Data[Line_C][43] = PORTD;
Image_Data[Line_C][44] = PORTD;Image_Data[Line_C][45] = PORTD;
Image_Data[Line_C][46] = PORTD;Image_Data[Line_C][47] = PORTD;
Image_Data[Line_C][48] = PORTD;Image_Data[Line_C][49] = PORTD;
Image_Data[Line_C][50] = PORTD;Image_Data[Line_C][51] = PORTD;
Image_Data[Line_C][52] = PORTD;Image_Data[Line_C][53] = PORTD;
Image_Data[Line_C][54] = PORTD;Image_Data[Line_C][55] = PORTD;
Image_Data[Line_C][56] = PORTD;Image_Data[Line_C][57] = PORTD;
Image_Data[Line_C][58] = PORTD;Image_Data[Line_C][59] = PORTD;
Image_Data[Line_C][60] = PORTD;Image_Data[Line_C][61] = PORTD;
Image_Data[Line_C][62] = PORTD;Image_Data[Line_C][63] = PORTD;
Image_Data[Line_C][64] = PORTD;Image_Data[Line_C][65] = PORTD;
Image_Data[Line_C][66] = PORTD;Image_Data[Line_C][67] = PORTD;
Image_Data[Line_C][68] = PORTD;Image_Data[Line_C][69] = PORTD;
Line_C++;
}
if(Line_C==ROW)
return;
}
//场中断处理函数
#pragma CODE_SEG NON_BANKED
interrupt 9 void VSYN_Interrupt(void)
{
TFLG1_C1F=1; //
TFLG1_C2F=1; //清除场同步中断
Line_C=0; //初始化采集行的下标
Point_C = 0;
TIE=0x02 ; //进入一场后开行中断,关闭场中断
}
补充内容 (2012-5-18 22:22):
中断序号改过来了,任然有问题,真想不通,路过的大神们哪。。。 |
|