中级会员
- 积分
- 455
- 威望
- 321
- 贡献
- 78
- 兑换币
- 2
- 注册时间
- 2010-11-30
- 在线时间
- 28 小时
|
#include <hidef.h> /* common defines and macros */
#include "derivative.h" /* derivative-specific definitions */
#include <MC9S12XS128.h>
void SCI0_Transmit(void);
void IOC_Contrl(void);
byte Image_data[38][120];
byte Point_C, YSYN_C, Line_Flag, m = 0,n=0;
byte Line_C=0;
unsigned char jiange;
//PLL初始化
void PLL_INC(void)
{
CLKSEL=0x00; //48mhz
SYNR=0XC0 | 0X05;
REFDV=0XC0 | 0X03;
PLLCTL_PLLON=1;
POSTDIV=0X00;
asm(nop);
asm(nop);
while(0==CRGFLG_LOCK); //锁相环锁定
CLKSEL_PLLSEL=1; //选定PLL时钟
}
/*-------串口初始化----------------------*/
void SCI0_Init()
{
SCI0BDL = (byte)((48000000 /* OSC freq *//2) / 57600 /* baud rate */ / 16 /*factor*/);
SCI0CR1 = 0X00; /*normal,no parity*/
SCI0CR2 = 0X0C; /*RIE=1,TE=1,RE=1, */
}
//输入捕捉初始化
void IOC_Init(void)
{
TIOS =0x00;//定时器通道0,1 为输入捕捉
TSCR1=0x80;//定时器使能
TCTL4=0x09;//通道0 捕捉上升沿通道1 捕捉下降沿
TIE=0x03; //通道0,1 中断使能
TFLG1=0xFF;//清中断标志位
}
//中断定义
#pragma CODE_SEG NON_BANKED
//IC1通道中断 场中断
interrupt 9 void VSYN_Interrupt(void)
{
TFLG1_C1F = 1; //清场中断
TFLG1_C0F = 1; //清行中断
Point_C = 0;
Line_C = 0; //行计数器
YSYN_C++;
SCI0DRL = 0X0A; //回车
while (!(SCI0SR1&0x80));
SCI0DRL = 0X0D;
while (!(SCI0SR1&0x80));
}
//IC0通道中断 行中断
interrupt 8 void HREF_Count(void)
{
TFLG1_C0F = 1;
Line_Flag = 0;
m++;
if ( m<12 || m>288 )
{
return;//判断是否从新的一场开始
}
if(m<=132)jiange=12;
else if(m>132&&m<=200) jiange=8;
else if(m>200&&m<=248) jiange=6;
else jiange=4;
if(m%jiange==0)
{
IOC_Contrl();
SCI0_Transmit();
Line_C++;
}
}
#pragma CODE_SEG DEFAULT
/*-------发射端程序----------------------*/
void SCI0_Transmit()
{
byte i, temp;
temp = SCI0SR1; //清零
SCI0DRH = 0;
for(i = 0;i < 119 ;i++)
{
if(Image_data[Line_C][i]>30 & Image_data[Line_C][i+1]>30)
SCI0DRL = 0x30;
else SCI0DRL = 0X31;
while (!(SCI0SR1&0x80)); /* wait for output buffer empty */
}
SCI0DRL = 0X0A; //回车
while (!(SCI0SR1&0x80));
SCI0DRL = 0X0D; //换行
while (!(SCI0SR1&0x80));
}
//计数控制
void IOC_Contrl(void)
{
//TIE = 0X00;
Image_data[Line_C][0] = PORTA;
Image_data[Line_C][1] = PORTA;
Image_data[Line_C][2] = PORTA;
Image_data[Line_C][3] = PORTA;
Image_data[Line_C][4] = PORTA;
Image_data[Line_C][5] = PORTA;
Image_data[Line_C][6] = PORTA;
Image_data[Line_C][7] = PORTA;
Image_data[Line_C][8] = PORTA;
Image_data[Line_C][9] = PORTA;
Image_data[Line_C][10] = PORTA;
Image_data[Line_C][11] = PORTA;
Image_data[Line_C][12] = PORTA;
Image_data[Line_C][13] = PORTA;
Image_data[Line_C][14] = PORTA;
Image_data[Line_C][15] = PORTA;
Image_data[Line_C][16] = PORTA;
Image_data[Line_C][17] = PORTA;
Image_data[Line_C][18] = PORTA;
Image_data[Line_C][19] = PORTA;
Image_data[Line_C][20] = PORTA;
Image_data[Line_C][21] = PORTA;
Image_data[Line_C][22] = PORTA;
Image_data[Line_C][23] = PORTA;
Image_data[Line_C][24] = PORTA;
Image_data[Line_C][25] = PORTA;
Image_data[Line_C][26] = PORTA;
Image_data[Line_C][27] = PORTA;
Image_data[Line_C][28] = PORTA;
Image_data[Line_C][29] = PORTA;
Image_data[Line_C][30] = PORTA;
Image_data[Line_C][31] = PORTA;
Image_data[Line_C][32] = PORTA;
Image_data[Line_C][33] = PORTA;
Image_data[Line_C][34] = PORTA;
Image_data[Line_C][35] = PORTA;
Image_data[Line_C][36] = PORTA;
Image_data[Line_C][37] = PORTA;
Image_data[Line_C][38] = PORTA;
Image_data[Line_C][39] = PORTA;
Image_data[Line_C][40] = PORTA;
Image_data[Line_C][41] = PORTA;
Image_data[Line_C][42] = PORTA;
Image_data[Line_C][43] = PORTA;
Image_data[Line_C][44] = PORTA;
Image_data[Line_C][45] = PORTA;
Image_data[Line_C][46] = PORTA;
Image_data[Line_C][47] = PORTA;
Image_data[Line_C][48] = PORTA;
Image_data[Line_C][49] = PORTA;
Image_data[Line_C][50] = PORTA;
Image_data[Line_C][51] = PORTA;
Image_data[Line_C][52] = PORTA;
Image_data[Line_C][53] = PORTA;
Image_data[Line_C][54] = PORTA;
Image_data[Line_C][55] = PORTA;
Image_data[Line_C][56] = PORTA;
Image_data[Line_C][57] = PORTA;
Image_data[Line_C][58] = PORTA;
Image_data[Line_C][59] = PORTA;
Image_data[Line_C][60] = PORTA;
Image_data[Line_C][61] = PORTA;
Image_data[Line_C][62] = PORTA;
Image_data[Line_C][63] = PORTA;
Image_data[Line_C][64] = PORTA;
Image_data[Line_C][65] = PORTA;
Image_data[Line_C][66] = PORTA;
Image_data[Line_C][67] = PORTA;
Image_data[Line_C][68] = PORTA;
Image_data[Line_C][69] = PORTA;
Image_data[Line_C][70] = PORTA;
Image_data[Line_C][71] = PORTA;
Image_data[Line_C][72] = PORTA;
Image_data[Line_C][73] = PORTA;
Image_data[Line_C][74] = PORTA;
Image_data[Line_C][75] = PORTA;
Image_data[Line_C][76] = PORTA;
Image_data[Line_C][77] = PORTA;
Image_data[Line_C][78] = PORTA;
Image_data[Line_C][79] = PORTA;
Image_data[Line_C][80] = PORTA;
Image_data[Line_C][81] = PORTA;
Image_data[Line_C][82] = PORTA;
Image_data[Line_C][83] = PORTA;
Image_data[Line_C][84] = PORTA;
Image_data[Line_C][85] = PORTA;
Image_data[Line_C][86] = PORTA;
Image_data[Line_C][87] = PORTA;
Image_data[Line_C][88] = PORTA;
Image_data[Line_C][89] = PORTA;
Image_data[Line_C][90] = PORTA;
Image_data[Line_C][91] = PORTA;
Image_data[Line_C][92] = PORTA;
Image_data[Line_C][93] = PORTA;
Image_data[Line_C][94] = PORTA;
Image_data[Line_C][95] = PORTA;
Image_data[Line_C][96] = PORTA;
Image_data[Line_C][97] = PORTA;
Image_data[Line_C][98] = PORTA;
Image_data[Line_C][99] = PORTA;
Image_data[Line_C][100] = PORTA;
Image_data[Line_C][101] = PORTA;
Image_data[Line_C][102] = PORTA;
Image_data[Line_C][103] = PORTA;
Image_data[Line_C][104] = PORTA;
Image_data[Line_C][105] = PORTA;
Image_data[Line_C][106] = PORTA;
Image_data[Line_C][107] = PORTA;
Image_data[Line_C][108] = PORTA;
Image_data[Line_C][109] = PORTA;
Image_data[Line_C][110] = PORTA;
Image_data[Line_C][111] = PORTA;
Image_data[Line_C][112] = PORTA;
Image_data[Line_C][113] = PORTA;
Image_data[Line_C][114] = PORTA;
Image_data[Line_C][115] = PORTA;
Image_data[Line_C][116] = PORTA;
Image_data[Line_C][117] = PORTA;
Image_data[Line_C][118] = PORTA;
Image_data[Line_C][119] = PORTA;
// TIE = 0X03;
}
void main(void)
{
/* put your own code here */
DisableInterrupts;
//DDRA = 0X00;
PLL_INC();
SCI0_Init();
IOC_Init();
EnableInterrupts;
for(;;)
{
_FEED_COP(); /* feeds the dog */
} /* loop forever */
/* please make sure that you never leave main */
} |
|