飞思卡尔智能小车programs

上传人:千****8 文档编号:183250909 上传时间:2021-06-01 格式:DOC 页数:25 大小:165.50KB
返回 下载 相关 举报
飞思卡尔智能小车programs_第1页
第1页 / 共25页
飞思卡尔智能小车programs_第2页
第2页 / 共25页
飞思卡尔智能小车programs_第3页
第3页 / 共25页
飞思卡尔智能小车programs_第4页
第4页 / 共25页
飞思卡尔智能小车programs_第5页
第5页 / 共25页
点击查看更多>>
资源描述

《飞思卡尔智能小车programs》由会员分享,可在线阅读,更多相关《飞思卡尔智能小车programs(25页珍藏版)》请在金锄头文库上搜索。

1、个人收集整理 勿做商业用途Main.c/*/:飞思卡尔智能小车 /版本说明Freescale CodeWarrior4。6 /:飞思卡尔MC9SDG128B单片机 /* /* common defines and macros */include MC9S12XS128.h /* derivative information /#include ”Stdio.hpragma LINK_INFO DERIVATIVE mc9s12xs128”uchar Switch1,Switch2;void main(void) int a; for(a=0;a3;a+) TSCR1 = 0x80; /* e

2、nable timer TCNT */ TSCR2 = 0x07; /* TCNT prescaler setup / while (TCNT != 0x0000); while (TCNT = 0x0000); /延时 1048.576ms init_all();/初始化 servo_angle = servo_center; DDRB = 0xff; DDRA = 0x00; / PUCR_PUPAE = 1; _asm nop; _asm nop; if (PORTA_PA5=0 & PORTA_PA6=1 & PORTA_PA7=1) Switch1 = 0; PORTB_PB3=1;

3、 wansu = 240; if(PORTA_PA4=0) qipao=1; PORTB_PB0=1; else qipao=0; else if(PORTA_PA6=0 & PORTA_PA5=1 & PORTA_PA7=1) Switch1 = 1; PORTB_PB4=1; wansu = 250; if(PORTA_PA4=0) qipao=1; PORTB_PB0=1; else qipao=0; else if(PORTA_PA7=0 PORTA_PA6=1 & PORTA_PA5=1 ) Switch1 = 2; PORTB_PB5=1; wansu = 260; if(PORT

4、A_PA4=0) qipao=1; PORTB_PB0=1; else qipao=0; else if(PORTA_PA5=0 & PORTA_PA6=0 & PORTA_PA7=1) Switch1 = 3; PORTB_PB3=1; PORTB_PB4=1; wansu = 230; if(PORTA_PA4=0) qipao=1; PORTB_PB0=1; else qipao=0; else if(PORTA_PA5=0 & PORTA_PA6=1 & PORTA_PA7=0) Switch1 = 4; PORTB_PB3=1; PORTB_PB5=1; wansu = 250; i

5、f(PORTA_PA4=0) qipao=1; PORTB_PB0=1; else qipao=0; else if(PORTA_PA5=1 PORTA_PA6=0 & PORTA_PA7=0) Switch1 = 5; PORTB_PB5=1; PORTB_PB4=1; wansu = 260; if(PORTA_PA4=0) qipao=1; PORTB_PB0=1; else qipao=0; else;/ PORTB_PB2 = 0 ;/ PORTB_PB1 = 1 ; /方向向前 for(;;) video_scan();/视频采集 offset_ps();/黑线偏移处理 devic

6、e_con();/执行器件控制 for(;;) /* wait forever */ /* please make sure that you never leave this function /Init。cinclude Stdio。h/ 中断初始化void TIM0_init(void) /输入捕捉中断 TIOS = 0xFE;/通道0置为输入捕捉 TSCR1 = 0x80; /IC/OC功能使能 TSCR2 = 0x00; /输出比较中断预分频 TCTL4 = 0x03; /EDG0B = EDG0A = 1;上升沿下降沿均捕捉 TFLG1 = 0x01; /清通道0中断标志 TIE

7、= 0x00;void RTI_Init(void) CRGINT_RTIE = 1; CRGFLG_RTIF = 1; PLLCTL_PRE = 1; RTICTL = 0x5F;/定时32.7msvoid IRQ_Init(void) IRQCR_IRQE = 1 ;/1 IRQ configured to respond only to falling edges IRQCR_IRQEN = 0;/0 IRQ interrupt disable/*名称:delay功能:延时参数:unsigned int d_time返回值:无*/延时us级,总线频率为80MHz下实测void delay

8、us(int us) int ii; if (us1) us=1; for(ii=0;iius;ii+);/延时ms级,总线频率为80MHz下实测 void delayms(int ms) int ii,jj; if (ms1) ms=1; for(ii=0;iims;ii+) for(jj=0;jj13340;jj+); /80MHz-1ms /*函数名:PLL_Init参数说明:uchar syn:合成参数uchar refdv:分解参数 (syn + 1)Fbus = - * Fosc; PLLCLK = Fbus 2;(refdv + 1)*/void PLL_Init() CLKSE

9、L=0X00;/disengage PLL to system PLLCTL_PLLON=1;/turn on PLL SYNR =0xc0 | 0x09; REFDV=0xc0 0x01; POSTDIV=0x00; /pllclock=2osc(1+SYNR)/(1+REFDV)=80MHz; _asm(nop); /BUS CLOCK=80M _asm(nop); while(!(CRGFLG_LOCK=1); /when pll is steady ,then use it; CLKSEL_PLLSEL =1; /engage PLL to system; /*名称:SCI_INIT功

10、能:初始化串口参数:无返回值:无*/ /*-串口初始化-/void SciInit() SCI0CR2 = 0x2c; /enable Receive Full Interrupt,RX enable,Tx enable SCI0BDH = 0x01; /busclk 80MHz,19200bps, SCI0BDL = 0x04; /SCI0BDL=busclk/(16SCI0BD)/发送一个字符void uart_putchar(uchar ch) /if(ch0xfb) ch = 0xFB; while(!(SCI0SR10x80) ; /keep waiting when not emp

11、ty SCI0DRL = ch;/发送一个字符数组void putdata8(uchar ptr,uchar row, uchar line) uchar i,j; uart_putchar(0xFF);/一次传输开始 for(i = 0;i row;i +) uart_putchar(0xFC); for(j = 0;j line;j +) uart_putchar(*(ptr +); uart_putchar(0xFE);/发送一个字符口串数组void putstr(char ch) uchar ptr = 0; while(chptr) uart_putchar((uchar)chptr+); /发送一个uint型数组void putdata16(uint *ptr,uchar row,uchar

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 高等教育 > 工学

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号