高级会员
- 积分
- 558
- 威望
- 402
- 贡献
- 66
- 兑换币
- 0
- 注册时间
- 2011-3-3
- 在线时间
- 45 小时
|
1贡献
我是个菜鸟,图像搞了很久都搞不出来,求助各位大哥!!
这是我根据上位机通信协议写的采集程序,但是什么都看不到,麻烦大家帮我看看。
- #include <hidef.h>
- #include <MC9S12XS128.h>
- /*************宏定义****************************/
- #define LINE_MAX 75 // 每行采集的点数,即列数
- #define ROW_MAX 95 // 采集到的行数
- /*************变量定义**************************/
- uchar a,b,c,temp;
- unsigned char Image[ROW_MAX][LINE_MAX];//图像数据
- uchar John[ROW_MAX][LINE_MAX];
- uchar row1; //图像数组行数
- uchar rowjd;
- uchar counter2;
- uint i;
- uint j;
- uint k;
- uint h;
- uint l;
- uint sign;
- static unsigned char space=0; //记录行中断
- /***************变量及数组初始化****************/
- void InitVariable(void)
- {
- counter2=0;
- // k=550;
- for(i=0;i<ROW_MAX;i++)
- for(j=0;j<LINE_MAX;j++)
- Image[i][j]=0;
- }
- /*************主频设置**************************/
- void Busclock(void) //05,01 48MHz 06,01 56MHz 07,01 64MHz 08,01 72MHz
- {
- CLKSEL=0x00;
- PLLCTL_PLLON=1;
- SYNR=0xC0 | 0x08;
- REFDV=0xC0 | 0x01;
- POSTDIV=0x00;
- _asm(nop);
- _asm(nop);
- while(!(CRGFLG_LOCK==1));
- CLKSEL_PLLSEL =1;
- }
- /*************定时器初始化***********************/
- void InitEct(void)
- {
- TIOS=0x00; //外部输入捕捉0,1通道
- TCTL4=0x09; //通道0上升沿触发,通道1下降沿触发
- TSCR1=0x80;
- TIE_C1I = 1; //场中断使能
- TIE_C0I = 1; //行中断使能
- }
- unsigned char SciRead()
- {
- if(SCI0SR1_RDRF==1) //表明数据从位移寄存器传输到SCI 数据寄存器
- {
- SCI0SR1_RDRF=1; //读取数据寄存器会将RDRF 清除重新置位
- return SCI0DRL; //返回数据寄存器的数据
- }
- }
- /*************串口初始化*************************/
- void SciInit()
- {
- SCI0BD=52; //9600bps Baud Rate=BusClock/(16*SCIBD)
- SCI0CR1=0; //正常8 位模式,无奇偶校验
- SCI0CR2=0X2C; //发送允许接受中断允许
- }
- /*************I/O初始化*************************/
- void InitIoport(void)
- {
- DDRA=0x00;
- }
- /**************发射端程序************************/
- void SciTx(uchar text)
- {
- while (!(SCI0SR1&0x80));
- SCI0DRH=0;
- SCI0DRL=text;
- }
- /**************发射端程序************************/
- void SciTxs(uchar *s)
- {
- while (!(SCI0SR1&0x80));
- SCI0DRH=0;
- while(*s!='\0'){
- SCI0DRL=*s;
- s++;
- }
- }
- /**************延时******************************/
- void Delay(int delay)
- { int i,j;
- for(i=0;i<delay;i++)
- {for(j=0;j<500;j++)
- asm nop;
- }
- }
- /*************主函数*****************************/
- void main()
- {
- DisableInterrupts;
- Busclock();
- InitEct();
- SciInit();
- InitVariable();
- InitIoport();
- EnableInterrupts;
- Delay(4000);
- for(;;)
- {
- }
- }
- /**********场中断处理******************************************/
- #pragma CODE_SEG __NEAR_SEG NON_BANKED
- void interrupt 9 Port1_interrupt(void)
- {
- TFLG1=0x02;
- TIE_C0I = 1; //开行中断
- row1 = 0;
- rowjd=0;
- sign=0;
- if(counter2==1)
- {
- TIE_C1I = 0;
- TIE_C0I = 0;
- }
- counter2++;
- }
- /**************行中断采集*************************/
- #pragma CODE_SEG __NEAR_SEG NON_BANKED //开始一段赋值是起延时的作用,调中心是加减就行了
- void interrupt 8 Port0_interrupt(void)
- {
- TFLG1=0x01; //清除行中断标志
- rowjd++;
- if(rowjd%2==0)
- {
- Image[row1][0] = PORTA;
- Image[row1][0] = PORTA;
- Image[row1][0] = PORTA;
- Image[row1][0] = PORTA;
- Image[row1][0] = PORTA;
- Image[row1][0] = PORTA;
- Image[row1][0] = PORTA;
- Image[row1][0] = PORTA;
- Image[row1][0] = PORTA;
- Image[row1][0] = PORTA;
- Image[row1][0] = PORTA;
- Image[row1][0] = PORTA;
- Image[row1][0] = PORTA;
- Image[row1][0] = PORTA;
- Image[row1][0] = PORTA;
- Image[row1][0] = PORTA;
- Image[row1][0] = PORTA;
- Image[row1][0] = PORTA;
- Image[row1][0] = PORTA;
- Image[row1][0] = PORTA;
- Image[row1][0] = PORTA;
- Image[row1][0] = PORTA;
- Image[row1][0] = PORTA;
- Image[row1][0] = PORTA;
- Image[row1][0] = PORTA;
- Image[row1][0] = PORTA;
- Image[row1][0] = PORTA;
- Image[row1][0] = PORTA;
- Image[row1][0] = PORTA;
- Image[row1][0] = PORTA;
- Image[row1][0] = PORTA;
- Image[row1][0] = PORTA;
- Image[row1][0] = PORTA;
- Image[row1][0] = PORTA;
- Image[row1][0] = PORTA;
- Image[row1][0] = PORTA;
- Image[row1][0] = PORTA;
- Image[row1][0] = PORTA;
- Image[row1][0] = PORTA;
- Image[row1][0] = PORTA;
- Image[row1][0] = PORTA;
- Image[row1][0] = PORTA;
- Image[row1][0] = PORTA;
- Image[row1][0] = PORTA;
- Image[row1][0] = PORTA;
- Image[row1][0] = PORTA;
- Image[row1][0] = PORTA;
- Image[row1][0] = PORTA;
- Image[row1][0] = PORTA;
- Image[row1][0] = PORTA;
- Image[row1][0] = PORTA;
- Image[row1][0] = PORTA;
- Image[row1][0] = PORTA;
- Image[row1][0] = PORTA;
- Image[row1][0] = PORTA;
- Image[row1][0] = PORTA;
- Image[row1][0] = PORTA;
- Image[row1][0] = PORTA;
- Image[row1][0] = PORTA;
- Image[row1][0] = PORTA;
- Image[row1][0] = PORTA;
- Image[row1][0] = PORTA;
- Image[row1][0] = PORTA;
- Image[row1][0] = PORTA;
- Image[row1][0] = PORTA;
- Image[row1][0] = PORTA;
- Image[row1][0] = PORTA;
- Image[row1][0] = PORTA;
- Image[row1][0] = PORTA;
- Image[row1][0] = PORTA;
- Image[row1][0] = PORTA;
- Image[row1][0] = PORTA;
- Image[row1][0] = PORTA;
- Image[row1][0] = PORTA;
- Image[row1][0] = PORTA;
- Image[row1][0] = PORTA;
- Image[row1][1] = PORTA;
- Image[row1][1] = PORTA;
- Image[row1][2] = PORTA;
- Image[row1][2] = PORTA;
- Image[row1][3] = PORTA;
- Image[row1][3] = PORTA;
- Image[row1][4] = PORTA;
- Image[row1][4] = PORTA;
- Image[row1][5] = PORTA;
- Image[row1][5] = PORTA;
- Image[row1][6] = PORTA;
- Image[row1][6] = PORTA;
- Image[row1][7] = PORTA;
- Image[row1][7] = PORTA;
- Image[row1][8] = PORTA;
- Image[row1][8] = PORTA;
- Image[row1][9] = PORTA;
- Image[row1][9] = PORTA;
- Image[row1][10] = PORTA;
- Image[row1][10] = PORTA;
- Image[row1][11] = PORTA;
- Image[row1][11] = PORTA;
- Image[row1][12] = PORTA;
- Image[row1][12] = PORTA;
- Image[row1][13] = PORTA;
- Image[row1][13] = PORTA;
- Image[row1][14] = PORTA;
- Image[row1][14] = PORTA;
- Image[row1][15] = PORTA;
- Image[row1][15] = PORTA;
- Image[row1][16] = PORTA;
- Image[row1][16] = PORTA;
- Image[row1][17] = PORTA;
- Image[row1][17] = PORTA;
- Image[row1][18] = PORTA;
- Image[row1][18] = PORTA;
- Image[row1][19] = PORTA;
- Image[row1][19] = PORTA;
- Image[row1][20] = PORTA;
- Image[row1][20] = PORTA;
- Image[row1][21] = PORTA;
- Image[row1][21] = PORTA;
- Image[row1][22] = PORTA;
- Image[row1][22] = PORTA;
- Image[row1][23] = PORTA;
- Image[row1][23] = PORTA;
- Image[row1][24] = PORTA;
- Image[row1][24] = PORTA;
- Image[row1][25] = PORTA;
- Image[row1][25] = PORTA;
- Image[row1][26] = PORTA;
- Image[row1][26] = PORTA;
- Image[row1][27] = PORTA;
- Image[row1][27] = PORTA;
- Image[row1][28] = PORTA;
- Image[row1][28] = PORTA;
- Image[row1][29] = PORTA;
- Image[row1][29] = PORTA;
- Image[row1][30] = PORTA;
- Image[row1][30] = PORTA;
- Image[row1][31] = PORTA;
- Image[row1][31] = PORTA;
- Image[row1][32] = PORTA;
- Image[row1][32] = PORTA;
- Image[row1][33] = PORTA;
- Image[row1][33] = PORTA;
- Image[row1][34] = PORTA;
- Image[row1][34] = PORTA;
- Image[row1][35] = PORTA;
- Image[row1][35] = PORTA;
- Image[row1][36] = PORTA;
- Image[row1][36] = PORTA;
- Image[row1][37] = PORTA;
- Image[row1][37] = PORTA;
- Image[row1][38] = PORTA;
- Image[row1][38] = PORTA;
- Image[row1][39] = PORTA;
- Image[row1][39] = PORTA;
- Image[row1][40] = PORTA;
- Image[row1][40] = PORTA;
- Image[row1][41] = PORTA;
- Image[row1][41] = PORTA;
- Image[row1][42] = PORTA;
- Image[row1][42] = PORTA;
- Image[row1][43] = PORTA;
- Image[row1][43] = PORTA;
- Image[row1][44] = PORTA;
- Image[row1][44] = PORTA;
- Image[row1][45] = PORTA;
- Image[row1][45] = PORTA;
- Image[row1][46] = PORTA;
- Image[row1][46] = PORTA;
- Image[row1][47] = PORTA;
- Image[row1][47] = PORTA;
- Image[row1][48] = PORTA;
- Image[row1][48] = PORTA;
- Image[row1][49] = PORTA;
- Image[row1][49] = PORTA;
- Image[row1][50] = PORTA;
- Image[row1][50] = PORTA;
- Image[row1][51] = PORTA;
- Image[row1][51] = PORTA;
- Image[row1][52] = PORTA;
- Image[row1][52] = PORTA;
- Image[row1][53] = PORTA;
- Image[row1][53] = PORTA;
- Image[row1][54] = PORTA;
- Image[row1][54] = PORTA;
- Image[row1][55] = PORTA;
- Image[row1][55] = PORTA;
- Image[row1][56] = PORTA;
- Image[row1][56] = PORTA;
- Image[row1][57] = PORTA;
- Image[row1][57] = PORTA;
- Image[row1][58] = PORTA;
- Image[row1][58] = PORTA;
- Image[row1][59] = PORTA;
- Image[row1][59] = PORTA;
- Image[row1][60] = PORTA;
- Image[row1][60] = PORTA;
- Image[row1][61] = PORTA;
- Image[row1][61] = PORTA;
- Image[row1][62] = PORTA;
- Image[row1][62] = PORTA;
- Image[row1][63] = PORTA;
- Image[row1][63] = PORTA;
- Image[row1][64] = PORTA;
- Image[row1][64] = PORTA;
- Image[row1][65] = PORTA;
- Image[row1][65] = PORTA;
- Image[row1][66] = PORTA;
- Image[row1][66] = PORTA;
- Image[row1][67] = PORTA;
- Image[row1][67] = PORTA;
- Image[row1][68] = PORTA;
- Image[row1][68] = PORTA;
- Image[row1][69] = PORTA;
- Image[row1][69] = PORTA;
- Image[row1][70] = PORTA;
- Image[row1][70] = PORTA;
- Image[row1][71] = PORTA;
- Image[row1][71] = PORTA;
- Image[row1][72] = PORTA;
- Image[row1][72] = PORTA;
- Image[row1][73] = PORTA;
- Image[row1][73] = PORTA;
- Image[row1][74] = PORTA;
- Image[row1][74] = PORTA;
- row1++;
- if(row1==ROW_MAX)
- {
- TIE_C0I = 0;
- TIE_C1I = 0;
- sign=1;
- }
- }
- }
- #pragma CODE_SEG NON_BANKED
- void interrupt 20 SCI0_re(void)
- {
- if(SciRead()=='s')
- {
- SciTx(0x55);
- SciTx(0xAA);
- SciTxs("095075");
- if(sign==1){
- for(i=0;i<ROW_MAX;i++)
- for(j=7;j<LINE_MAX-7;j++){
- SciTx(Image[i][j]);
- if(j=LINE_MAX-7)
- SciTx('\n');
- }
- }
- }
- }
复制代码 |
|