MSP430G2553制作的自行车测度系统

上传人:夏** 文档编号:484286494 上传时间:2022-11-30 格式:DOCX 页数:13 大小:127.12KB
返回 下载 相关 举报
MSP430G2553制作的自行车测度系统_第1页
第1页 / 共13页
MSP430G2553制作的自行车测度系统_第2页
第2页 / 共13页
MSP430G2553制作的自行车测度系统_第3页
第3页 / 共13页
MSP430G2553制作的自行车测度系统_第4页
第4页 / 共13页
MSP430G2553制作的自行车测度系统_第5页
第5页 / 共13页
点击查看更多>>
资源描述

《MSP430G2553制作的自行车测度系统》由会员分享,可在线阅读,更多相关《MSP430G2553制作的自行车测度系统(13页珍藏版)》请在金锄头文库上搜索。

1、MSP430G2553 制作的自行车测度系统一,功能介绍:本系统主要用于安装在自行车上测量自行车的运行速度和行驶距离。 然后将速度和距离信息显示在显示在 LCD显示屏上。 (1) 处理器选用的是 TI 的MSP430G2553单片机(2) 测速装置选用的是霍尔器件,在车圈上固定一个磁铁,然后430 连接霍尔器件,通过输入捕获功能测量车轮的转动输出的脉冲的周期 在加上事先计算出车轮的直径就可计 算出车子的运行速度和行驶距离(3) 显示屏选用的是 NOKIA5110 LCD的显示屏,此显示屏的成本比较低,可以满足我的显示要求。(4) 整个系统有两个按键,一个是距离清零按键,按下该按键可以将显示的距

2、离清零,这样方便测量起始地和目的地的距离, 另外一个按键是用于打开 LCD的背光的,用于夜 晚 使用。当夜晚光线比较暗时,按下该按键 LCD的背光打开,方便看清楚显示的东西。在按一下背光熄灭。(5) 整个系统的供电的用到 2 节 7 号电池供电,当平常车子没有运行的时候, 430处于低功耗状态。耗电比较少,现在测速系统已将安装在我车子上正常工作 3 个月了二,系统框图图 1 是整个系统的框图 . LCD显示屏和 MSP430G2553的连接采用的 SPI 接口,霍尔传感器和按键和 430 之间是 IO 口连接。三,系统原理图图 2 是整个系统的原理图四,程序代码/* *#include#inc

3、lude#include#includeunsigned char Count, First_Time;unsigned int REdge1, REdge2, FEdge;unsigned char MST_Data, SLV_Data;#define DC P2OUT = P2OUT|(15)#define SCE P2OUT = P2OUT|(14)#define CLK_H P1OUT=P1OUT|(15)#define CLK_L P1OUT=P1OUT&(15)#define Data_H P1OUT=P1OUT|(17)#define Data_L P1OUT=P1OUT&(17

4、)#define u8 unsigned char#define u16 unsigned inttypedef structu8 x;u8 y;point;/*-5110屏幕尺寸和功能宏定义-*/#define DATA 1 /数据#define CMD 0 /命令#define LCD_X 84 / 液晶屏横坐标宽度#define LCD_ROW LCD_X /液晶屏列宽度void LCD_write_byte(unsigned char dat, unsigned char command);void LCD_init(void);void LCD_init(void);void LCD

5、_set_XY(unsigned char X, unsigned char Y);void LCD_clear(void);void LCD_write_char(unsigned char c);void LCD_write_String(unsignedchar X,unsigned char Y,unsigned char *s);void LCD_write_byte(unsigned char dat, unsigned char command)unsigned int i;/ LCD_SCE = 0; /5110 P2OUT &=BIT4;片选有效,允许输入数据if (comm

6、and = 0) / / LCD_DC = 0; P2OUT &=BIT5; else / LCD_DC = 1;写命令P2OUT |=BIT5;/ 写数据for (i=0;i8;i+)CLK_L;/spi_clk=0;if(dat & 0x80)=0x80)Data_H;elseData_L;CLK_H; / spi_clk=1;dat=(dat1);P2OUT |=BIT4;void LCD_init(void)P2OUT &=BIT4;P1OUT &= BIT4;P1OUT |= BIT4;LCD_write_byte(0x21, 0); / LCD 模式设置 : 芯片活动,水平寻址,使

7、用扩展指令LCD_write_byte(0xc8, 0); /设置液晶偏置电压LCD_write_byte(0x06, 0); / LCD_write_byte(0x13, 0); / 1:48温度校正LCD_write_byte(0x20, 0); /使用基本命令,V=0,水平寻址LCD_clear(); /清屏LCD_write_byte(0x0c, 0); / P2OUT |=BIT4;设定显示模式,正常显示void LCD_set_XY(unsigned char X, unsigned char Y)LCD_write_byte(0x80 | X, 0); / X行( 横坐标 )LC

8、D_write_byte(0x40 | Y, 0); / column 列( 纵坐标 )/*-/LCD_clear: LCD清屏函数-*/void LCD_clear(void)unsigned char t;unsigned char k;LCD_set_XY(0,0);for(t=0;t6;t+)for(k=0;k84;k+)LCD_write_byte(0x00,1);void LCD_write_char(unsigned char c)unsigned char i;c-=0x20; /ASCII码减去 0x20for (i=0; i6; i+)LCD_write_byte(ASCI

9、I_6_8c, 1);void LCD_write_String(unsignedchar X,unsigned char Y,unsignedchar *s)LCD_set_XY(X,Y);while (*s) /等效 *s!=0LCD_write_char(*s);s+;static float speed;static unsigned char display10;static unsigned char display210;static unsigned int temp ;static unsigned int distance=0;static float Period;sta

10、tic float Distance_km;int main(void)volatile unsigned int i;unsigned char lcd_buf684;WDTCTL = WDTPW + WDTHOLD; / Stop watchdog timerP1DIR |= BIT0; / P1.0/LED OutputP1OUT &= BIT0; / LED offif (CALBC1_8MHZ=0xFF) / If calibration constant erasedwhile(1); / do not load, trap CPU!DCOCTL = 0; / Select low

11、est DCOx and MODx settingsBCSCTL1 = CALBC1_8MHZ; / Set DCO to 8MHzDCOCTL = CALDCO_8MHZ;P1DIR &= BIT2;P1SEL |= BIT2;P2DIR &= BIT2;P2DIR &= BIT1;P2IES |=BIT2+BIT1;P2IE |=BIT2+BIT1;P1DIR |= BIT0;P1DIR|=BIT4|BIT5|BIT7;TA0CCTL1 = CAP + CM_3 + CCIE + SCS + CCIS_0;TA0CTL |= TASSEL_1 + MC_2 + TACLR; / ACLK, Cont Mode; start timerCount = 0x0;First_Time = 0x01;P2OUT = 0x00;P2DIR |=BIT5+BIT4 ;P1DIR |=BIT4 ;_EINT();P1OUT &= BIT4; / Now with SPI signals initialized,P1OUT |= BIT4; / reset slaveLCD_init(); /初始化 LCD模

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

当前位置:首页 > 办公文档 > 演讲稿/致辞

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