MSP430F5529 LAB CODE的實驗例程
0.png (45.56 KB, 下載次數(shù): 52)
下載附件
2018-7-10 19:09 上傳
單片機源程序如下:
- //***************************************************************************//
- // //
- // MSP-EXP430F5529 LAB CODE //
- // //
- // LAB1main- Main file //
- // //
- //***************************************************************************//
- #include <stdint.h>
- #include "msp430.h"
- #include "HAL_PMM.h"
- #include "HAL_UCS.h"
- #include "HAL_Board.h"
- #include "HAL_Buttons.h"
- #include "HAL_Dogs102x6.h"
- #include "HAL_Menu.h"
- #include "HAL_Wheel.h"
- #include "LPM.h"
- #include "PMM.h"
- #include "lab1.h"
- uint16_t timeoutCounter;
- // This image has been created by ImageDog using 'ti_bug.jpg'
- static const uint8_t tiBug[] =
- {
- 0x42, // Image width in pixels
- 0x08, // Image height in rows (1 row = 8 pixels)
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
- 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f,
- 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
- 0xff, 0xff, 0xff, 0xff, 0x0f, 0x0f, 0x0f, 0x0f, 0x08, 0x00, 0x00, 0x0f, 0xcf, 0xcf, 0xcf, 0xcf,
- 0xcf, 0xc8, 0x00, 0x00, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f,
- 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
- 0xff, 0xff, 0xff, 0xff, 0xf8, 0xf0, 0xf0, 0xf0, 0xf0, 0xc0, 0x00, 0x07, 0xff, 0xff, 0xff, 0xff,
- 0xff, 0xfe, 0xc0, 0x00, 0x00, 0xf0, 0xf0, 0xf0, 0xf0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
- 0xff, 0xff, 0xff, 0x01, 0x00, 0x00, 0x00, 0x70, 0x7c, 0x7e, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f,
- 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
- 0xff, 0xff, 0xff, 0xff, 0xff, 0xcf, 0x0f, 0x0f, 0x0f, 0x00, 0x00, 0x01, 0x3f, 0xff, 0xff, 0xff,
- 0xff, 0xff, 0xf0, 0x00, 0x01, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
- 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xc0, 0xe0,
- 0xf0, 0xfc, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
- 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfc, 0x80, 0x00, 0x0e, 0xfe, 0xfe, 0xfe,
- 0xfe, 0xfe, 0xfc, 0x80, 0x00, 0x0e, 0xfe, 0xfe, 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
- 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x80, 0xe0, 0xf0, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf0, 0xe0, 0xc0, 0x80,
- 0x80, 0x80, 0xc0, 0xc0, 0xf0, 0xf8, 0xfe, 0xff, 0xff, 0xff, 0xff, 0x03, 0x03, 0x01, 0x01, 0x01,
- 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x0f, 0xff, 0xff, 0xff, 0xfe, 0xfe,
- 0xfc, 0xf8, 0xf0, 0xf0, 0xe0, 0xe0, 0xc0, 0xc0, 0xc0, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xe0, 0xf8, 0xfe, 0xff, 0xff, 0xff,
- 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf8, 0xe0, 0xc0, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80,
- 0xc0, 0xf0, 0xf0, 0xf8, 0xfc, 0xfe, 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x02, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
- };
- void main(void)
- {
- uint8_t contrast = *((unsigned char *)contrastSetpointAddress); //讀取FLASH中對比度值
- uint8_t brightness = *((unsigned char *)brightnessSetpointAddress); //讀取FLASH中背光值
- // Initialize accelerometer offset from flash
- // Cma3000_setAccel_offset(*((unsigned char *)accelXcalibrationAddress), //初始化加速度偏移量
- // *((unsigned char *)accelYcalibrationAddress),
- // *((unsigned char *)accelZcalibrationAddress));
- // Stop WDT
- WDTCTL = WDTPW + WDTHOLD; //關閉看門狗
- // Basic GPIO initialization
- Board_init(); //初始化GPIO
- // Set Vcore to accomodate for max. allowed system speed
- SetVCore(3); //設VCore為最大
- // Use 32.768kHz XTAL as reference
- LFXT_Start(XT1DRIVE_0); //利用LFXT1(32.768kHZ)作為時鐘參考
- // Set system clock to max (25MHz)
- Init_FLL_Settle(25000, 762); //利用FLL(鎖頻環(huán))將系統(tǒng)時鐘設為最大25MHZ
- SFRIFG1 = 0; //清中斷標志
- SFRIE1 |= OFIE; //使能晶振失效中斷
- // Globally enable interrupts
- __enable_interrupt(); //使能全局中斷
- // Setup real time clock
- SetupRTC(); //設置實時時鐘
- // Set up LCD
- Dogs102x6_init(); //初始化LCD
- Dogs102x6_backlightInit(); //背光初始化
- // Contrast not programed in Flash Yet
- if (contrast == 0xFF) //若當前FLASH中無對比度值,則將對比度值設為11(默認)
- // Set Default Contrast
- contrast = 11;
- // Brightness not programed in Flash Yet
- if (brightness == 0xFF) //若當前FLASH中無背光值,則將背光值設為11(默認)
- // Set Default Brightness
- brightness = 11;
- Dogs102x6_setBacklight(brightness); //設置初始背光值
- Dogs102x6_setContrast(contrast); //設置初始對比度值
- Dogs102x6_clearScreen(); //清屏
- // Set up wheel
- Wheel_init(); //初始化齒輪電位計
- Buttons_init(BUTTON_ALL); //初始化按鍵
- Buttons_interruptEnable(BUTTON_ALL); //使能所有按鍵中斷
- buttonsPressed = 0; //鍵值清零
- // Display TI logo
- Dogs102x6_imageDraw(tiBug, 0, 16); //顯示TI圖案
- // Wait for button press
- while (!buttonsPressed) //等待按鍵被按下,或者超時退出等待
- {
- for (timeoutCounter = 0; timeoutCounter < 0xFFFF; timeoutCounter++)
- {
- if (buttonsPressed)
- break;
- __delay_cycles(1000);
- }
- //Timeout break
- break; //超時退出
- }
- Dogs102x6_clearScreen();
- buttonsPressed = 0;
- //顯示文字說明:
- Dogs102x6_stringDraw(3, 0, " Welcome to ", DOGS102x6_DRAW_NORMAL);
- Dogs102x6_stringDraw(4, 0, " MSP-EXP430F5529 ", DOGS102x6_DRAW_NORMAL);
- Dogs102x6_stringDraw(6, 0, "Wait for a moment", DOGS102x6_DRAW_INVERT);
- Dogs102x6_stringDraw(7, 0, "or press S1 | S2 ", DOGS102x6_DRAW_INVERT);
- // Wait for button press
- while (!buttonsPressed) //等待按鍵被按下,或者超時退出等待
- {
- for (timeoutCounter = 0; timeoutCounter < 0xFFFF; timeoutCounter++)
- {
- if (buttonsPressed)
- break;
- __delay_cycles(2000);
- }
- //Timeout break
- break;
- }
- // 主循環(huán)
- while (1)
- {
- lab1(); //試驗一程序
- }
- }
復制代碼
所有資料51hei提供下載:
LAB1.zip
(2.69 MB, 下載次數(shù): 39)
2018-7-10 12:02 上傳
點擊文件名下載附件
下載積分: 黑幣 -5
|