中级会员
- 积分
- 377
- 威望
- 214
- 贡献
- 113
- 兑换币
- 0
- 注册时间
- 2009-1-15
- 在线时间
- 25 小时
|
以下是整个程序,运行后并没有输出期望的结果,应该是64*107个数,但输出的不对。另外我设置了一个变量K,赋值02输出却是FF。求助高手,主要是串口部分。
#include <hidef.h> /* common defines and macros */
#include <mc9s12dg128.h> /* derivative information */
#pragma LINK_INFO DERIVATIVE "mc9s12dg128b"
#define VIDEO_SAMPLE INTCR_IRQEN=1 //外部中断使能
#define NO_SAMPLE INTCR_IRQEN=0
#define LINE_MAX 107 // 每行采集的点数,即列数
#define ROW_MAX 64 // 采集到的行数
static unsigned char Video_flag;//行信号,采集标志信号。
unsigned char Image[ROW_MAX][LINE_MAX];//图像数据。
unsigned char black_x[ROW_MAX];//存放黑点
static unsigned char Image_get=0;//记录采集图像行数
static unsigned char row1;//图像数组行数
/************************************************************************************/
void Video_Init(void)
{
HPRIO = (unsigned char)(Virq & 0xff); //将IRQ优先级置为最高
INTCR |= INTCR_IRQE_MASK; // Failing sensitive only
// INTCR &=~INTCR_IRQEN_MASK; // Disable IRQ
INTCR_IRQEN=0; //Disable IRQ interrupt
PERH |=0X01; //PULL UP H0 上拉,
PUCR_PUPAE=1; // PortA Pull up 上拉,接收图像数据
PIEH_PIEH0=0; //0000 0001 H0 口中断使能
}
/******************************倍频*****************************************/
void PLLInit(void)
{ //BUS-CLOCK=PLL-CLOCK/2=32M
REFDV = 1;
SYNR =3;
while (!CRGFLG_LOCK); // wait here till the PLL is locked.
CLKSEL|=0x80; // switch the bus clock to the PLL.
}
/***************************IO口初始化************************************/
void IOPortInit(void)
{
DDRA=0X00;
DDRB=0XFF;
}
/*-------串口初始化----------------------*/
void SciInit(){
SCI0BDL = (unsigned char)((16000000UL /* OSC freq */ / 2) / 9600 /* baud rate */ / 16 /*factor*/);
SCI0CR1=0; /*normal,no parity*/
SCI0CR2=0X2C; /*RIE=1,TE=1,RE=1*/
}
/*-------发射端程序----------------------*/
void SciTx(unsigned char text){
while (!(SCI0SR1&0x80)); /* wait for output buffer empty */
SCI0DRH=0;
SCI0DRL=text;
}
void Delay(int delay)
{ int i,j;
for(i=0;i<delay;i++)
{for(j=0;j<250;j++)
asm nop;
}
}
/************************************主函数************************************/
void main(void)
{
unsigned char i,j;
unsigned char k;
DisableInterrupts;
PLLInit();
IOPortInit();
SciInit();
EnableInterrupts;
Delay(4000);
DisableInterrupts;
PORTB=0xf0;
for(i=0;i<ROW_MAX;i++)
{
for(j=0;j<LINE_MAX;j++)
SciTx(Image[i][j]);
}
PORTB=0x0f;
k=0x02;
SciTx(k);
for(;;)
{
}
}
/*****************************图像获得 *************************************/
/******************************行中断*****************************************/
#pragma CODE_SEG NON_BANKED
void interrupt 6 Port0_interrupt(void)
{
TFLG1=0x01; //清除行中断标志
if(Video_flag&&(row1%9)==0)
{
Video_flag=0;
return;
}
Image[row1][0] = PORTA;
Image[row1][1] = PORTA;__asm nop;
Image[row1][2] = PORTA;
Image[row1][3] = PORTA;
Image[row1][4] = PORTA;
Image[row1][5] = PORTA;
Image[row1][6] = PORTA;
Image[row1][7] = PORTA;
Image[row1][8] = PORTA;
Image[row1][9] = PORTA;
Image[row1][10] = PORTA;
Image[row1][11] = PORTA;
Image[row1][12] = PORTA;
Image[row1][13] = PORTA;
Image[row1][14] = PORTA;
Image[row1][15] = PORTA;
Image[row1][16] = PORTA;
Image[row1][17] = PORTA;__asm nop;
Image[row1][18] = PORTA;
Image[row1][19] = PORTA;
Image[row1][20] = PORTA;
Image[row1][21] = PORTA;
Image[row1][22] = PORTA;
Image[row1][23] = PORTA;
Image[row1][24] = PORTA;
Image[row1][25] = PORTA;
Image[row1][26] = PORTA;
Image[row1][27] = PORTA;
Image[row1][28] = PORTA;
Image[row1][29] = PORTA;
Image[row1][30] = PORTA;
Image[row1][31] = PORTA;__asm nop;
Image[row1][32] = PORTA;
Image[row1][33] = PORTA;
Image[row1][34] = PORTA;
Image[row1][35] = PORTA;
Image[row1][36] = PORTA;
Image[row1][37] = PORTA;
Image[row1][38] = PORTA;
Image[row1][39] = PORTA;__asm nop;
Image[row1][40] = PORTA;
Image[row1][41] = PORTA;
Image[row1][42] = PORTA;
Image[row1][43] = PORTA;
Image[row1][44] = PORTA;
Image[row1][45] = PORTA;
Image[row1][46] = PORTA;
Image[row1][47] = PORTA;
Image[row1][48] = PORTA;
Image[row1][49] = PORTA;
Image[row1][50] = PORTA;
Image[row1][51] = PORTA;
Image[row1][52] = PORTA;
Image[row1][53] = PORTA;
Image[row1][54] = PORTA;
Image[row1][55] = PORTA;
Image[row1][56] = PORTA;
Image[row1][57] = PORTA;
Image[row1][58] = PORTA;
Image[row1][59] = PORTA;
Image[row1][60] = PORTA;
Image[row1][61] = PORTA;
Image[row1][62] = PORTA;
Image[row1][63] = PORTA;
Image[row1][64] = PORTA;
Image[row1][65] = PORTA;
Image[row1][66] = PORTA;
Image[row1][67] = PORTA;
Image[row1][68] = PORTA;
Image[row1][69] = PORTA;
Image[row1][70] = PORTA;
Image[row1][71] = PORTA;
Image[row1][72] = PORTA;
Image[row1][73] = PORTA;
Image[row1][74] = PORTA;
Image[row1][75] = PORTA;
Image[row1][76] = PORTA;
Image[row1][77] = PORTA;
Image[row1][78] = PORTA;
Image[row1][79] = PORTA;
Image[row1][80] = PORTA;
Image[row1][81] = PORTA;
Image[row1][82] = PORTA;
Image[row1][83] = PORTA;
Image[row1][84] = PORTA;
Image[row1][85] = PORTA;
Image[row1][86] = PORTA;
Image[row1][87] = PORTA;
Image[row1][88] = PORTA;
Image[row1][89] = PORTA;
Image[row1][90] = PORTA;
Image[row1][91] = PORTA;
Image[row1][92] = PORTA;
Image[row1][93] = PORTA;
Image[row1][94] = PORTA;
Image[row1][95] = PORTA;
Image[row1][96] = PORTA;
Image[row1][97] = PORTA;
Image[row1][98] = PORTA;
Image[row1][99] = PORTA;
Image[row1][100] = PORTA;__asm nop;
Image[row1][101] = PORTA;
Image[row1][102] = PORTA;
Image[row1][103] = PORTA;
Image[row1][104] = PORTA;
Image[row1][105] = PORTA;
Image[row1][106] = PORTA;
Video_flag=1;
row1++;
}
#pragma CODE_SEG DEFAULT_ROM
/********场信号中断入口***************/
#pragma CODE_SEG NON_BANKED
void interrupt 25 PortH_ISR(void)
{
PIFH=0XFF; //Clear Flag H 中断标志位,1 有变化信号产生
row1 = 0;
if(Image_get==1)
{
NO_SAMPLE;
PIEH_PIEH0=0;
Image_get=0;
}
else
{
Image_get++;
}
if(Image_get>1)
{
Image_get=0;
}
}
#pragma CODE_SEG DEFAULT_ROM |
|