📄 lqmain.c
字号:
/**************************************************************************************
龙丘MC9S12(DG128)多功能开发板V4.0
Designed by Chiu Sir
E-mail:chiusir@163.com
软件版本:V1.1
最后更新:2008年12月26日
相关信息参考下列地址:
博客: http://longqiu.21ic.org
淘宝店:http://shop36265907.taobao.com
------------------------------------
Code Warrior 4.7
Target : MC9S12DG128B
Crystal: 16.000Mhz
busclock:16.000MHz
pllclock:32.000MHz
============================================
下面的类型定义请拷贝到左侧窗口的Libraries文件加下面的mc9s12dg128.h中:
typedef unsigned char U8;
typedef unsigned int U16;
typedef unsigned long U32;
typedef signed char S8;
typedef signed int S16;
============================================
演示程序使用说明:
本程序用来控制智能车舵机Futaba S3010的,PWM0输出方波周期是20毫秒,操作方法:
左方向键:舵机左转
右方向键:舵机右转
1.插上液晶屏到LCD接口;
2.插上DC5V电源并打开开关;
3.然后出现龙丘LOGO;
4.液晶屏上显示:DTY:xxxx为PWM的duty circle值。
5.没有开发板可以把串口速率设置为9600,通过PC键盘的"r"和"l"进行舵机的方向控制。
*****************************************************************************************/
#include <hidef.h> /* common defines and macros */
#include <mc9s12dg128.h> /* derivative information */
#include <stdio.h>
#include "LQprintp.h"
#include "LQinit.h"
#include "LQ12864.h"
#pragma LINK_INFO DERIVATIVE "mc9s12dg128b"
#ifndef U8
typedef unsigned char U8;
typedef unsigned int U16;
typedef unsigned long U32;
typedef signed char S8;
typedef signed int S16;
#endif
void Dly_ms(int ms)
{
int ii,jj;
if (ms<1) ms=1;
for(ii=0;ii<ms;ii++)
for(jj=0;jj<2770;jj++); //32MHz--1ms
}
//-----------------------------------------------------
U8 Scan_Key(void)
{
Dly_ms(10);
if(PTIH_PTIH7==0) return 'o'; // OK
else if(PTIH_PTIH5==0) return 'd'; // DWON
else if(PTIH_PTIH6==0) return 'c'; // ESC
else if(PTIH_PTIH4==0) return 'r'; // RIGHT
else if(PTIH_PTIH3==0) return 'l'; // LEFT
else if(PTIH_PTIH2==0) return 'u'; // UP
else if(PTIH_PTIH1==0) return 'b'; // F2
else if(PTIH_PTIH0==0) return 'a'; // F1
else return 0xff;
}
U8 u8_RCV_Ch=0xff;
//====================中断函数==================================
#pragma CODE_SEG __NEAR_SEG NON_BANKED
void interrupt 20 SCI0_ISR(void)
{
SCI0CR2_RIE=0;
//此处为串口中断需要处理的事情
uart_putchar(u8_RCV_Ch=uart_getkey());
PORTB_BIT2=~PORTB_BIT2;
SCI0CR2_RIE = 1;
}
//====================main()==================================
#pragma CODE_SEG DEFAULT
void main(void)
{
S8 txtbuf[16]="";
U8 u8_key=0;
Init_Dev();
LCD_Init();
PORTB=0x00;
putstr("\nLongQiu s.&t.\n");
Draw_LQLogo();
Dly_ms(2000);
LCD_CLS();
LCD_Print(36,0,"龙丘科技");
LCD_Print(40,2,"开发板");
LCD_P6x8Str(19,4,"chiusir@163.com");
Dly_ms(2000);
PORTB=0xFF;
EnableInterrupts;
//LCD_P8x16Str(10,1,"");
for(;;)
{
//----------小键盘功能部分---------------------------
if((u8_key=Scan_Key())!=0xff)
u8_RCV_Ch=u8_key;
switch(u8_RCV_Ch)
{
case 'l':
if(PWMDTY01>1050) PWMDTY01-=5;
u8_RCV_Ch=0xff;
break;
case 'r':
if(PWMDTY01<1850) PWMDTY01+=5;
u8_RCV_Ch=0xff;
break;
default:
break;
}//switch(u8_RCV_Ch)
Dly_ms(50);
//----------PWM0----------------------------------
sprintf(txtbuf,"DTY:%d ",PWMDTY01);
LCD_P8x16Str(10,5,txtbuf);
printp("\n duty circle: %d",PWMDTY01);
//--------------------------------------------------------
PORTB_BIT0=~PORTB_BIT0;
}//for(;;)
} //main
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -