📄 ccdbit.c
字号:
/** ###################################################################
** Filename : CCDBIT.C
** Project : CCDBIT
** Processor : MC9S12DG128BCPV
** Version : Driver 01.11
** Compiler : Metrowerks HC12 C Compiler
** Date/Time : 2008-3-21, PM 07:45
** Abstract :
** Main module.
** Here is to be placed user's code.
** Settings :
** Contents :
** No public methods
**
** (c) Copyright UNIS, spol. s r.o. 1997-2005
** UNIS, spol. s r.o.
** Jundrovska 33
** 624 00 Brno
** Czech Republic
** http : www.processorexpert.com
** mail : info@processorexpert.com
** ###################################################################*/
/* MODULE CCDBIT */
/* Including used modules for compiling procedure */
#include "Cpu.h"
#include "PWM8.h"
/* Include shared modules, which are used for whole project */
#include "PE_Types.h"
#include "PE_Error.h"
#include "PE_Const.h"
#include "IO_Map.h"
int white_point,black_point;
int ccd_line_num,threeline;
int see[3];
int midsee[10];
int ccd_sum;
int ccd_ave;
int ccd_ave_key;
int ccd_lim;
int road;
void delay(unsigned int count){
unsigned int iu;
for(iu=0;iu<=count;iu++){
asm{
nop
}
}
}
unsigned int mid_val(unsigned int big0,unsigned int big1,unsigned int big2){
unsigned int biger[3];
unsigned int hh;
unsigned int kk;
unsigned int t;
biger[0] =big0;
biger[1] =big1;
biger[2] =big2;
for (hh=0;hh<=1;hh++)
{
for (kk=hh+1;kk<=2;kk++)
{
if(biger[hh]<biger[kk])
{
t=biger[hh];
biger[hh]=biger[kk];
biger[kk]=t;
}
}
}
return biger[1];
}
void ccd_get(){
while(PORTA_BIT0);
while(!PORTA_BIT0);
delay(1100);
for (ccd_line_num=1;ccd_line_num<=10;ccd_line_num++) {
midsee[ccd_line_num]=0;
for (threeline=0;threeline<3;threeline++)
{
see[threeline]=0;
white_point=0;
black_point=0;
next_line:
while(PORTA_BIT1);
while(!PORTA_BIT1);
while(PORTA_BIT2);
while(!PORTA_BIT2) {white_point++;}
while(PORTA_BIT2) {black_point++;}
if(white_point>0&&white_point<=119){
if(black_point>50){delay(400);goto next_line;}
else{
see[threeline]=white_point+black_point;
}
}
}
midsee[ccd_line_num]=mid_val(see[0],see[1],see[2]);
delay(100);
}
}
void ccd_find(){
ccd_sum=0;
ccd_ave_key=30;
ccd_lim=0;
/*for(ccd_line_num=1;ccd_line_num<=10;ccd_line_num++){
if(midsee[ccd_line_num]>60){ PORTB++;Cpu_Delay100US(1000); }
}*/
if((midsee[5]>40)&&(midsee[5]<80)){
road=0;
}else if(midsee[5]>=80){
road=-1;
}else if(midsee[5]<=40){
road=1;
}
}
void road_pwm(){
ccd_lim=midsee[5]-60;
if(road==0){
if(PWMDTY01<58900){PWMDTY01=PWMDTY01+50;}else if(PWMDTY01>59100) {PWMDTY01=PWMDTY01-50;}else{};
}else if(road==1){
if(PWMDTY01<60300){PWMDTY01=PWMDTY01+50;}else if(PWMDTY01>60500) {PWMDTY01=PWMDTY01-50;}else{};
}else if(road==-1){
if(PWMDTY01<58100){PWMDTY01=PWMDTY01+50;}else if(PWMDTY01>58300) {PWMDTY01=PWMDTY01-50;}else{};
}
}
void main(void)
{
/*** Processor Expert internal initialization. DON'T REMOVE THIS CODE!!! ***/
PE_low_level_init();
/*** End of Processor Expert internal initialization. ***/
DDRA=0X00;
DDRB=0XFF;
PORTB=0X00;
PWMDTY01=59000;
for(;;){
ccd_get();
ccd_find();
road_pwm();
}
/*** Processor Expert end of main routine. DON'T MODIFY THIS CODE!!! ***/
for(;;){}
/*** Processor Expert end of main routine. DON'T WRITE CODE BELOW!!! ***/
} /*** End of main routine. DO NOT MODIFY THIS TEXT!!! ***/
/* END CCDBIT */
/*
** ###################################################################
**
** This file was created by UNIS Processor Expert 2.96 [03.76]
** for the Freescale HCS12 series of microcontrollers.
**
** ###################################################################
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -