⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.c

📁 This a simple example project for the MSP430 series MCU and the GCC port of the mspgcc project. The
💻 C
字号:
/*see README.txt for details.chris <cliechti@gmx.net>*/#include "hardware.h"#include <stdlib.h>#include <stdio.h>#include "lcd.h"//the font file has no separate header file, it just provides//the font in this array:extern const char lcdfont[64];//redirect stdio to LCDint putchar(int c) {    lcdPutc(c);    return 1;}//global vars to store the timeint h, m, s;/**This one is executed once a second. it counts seconds, minutes, hours - heyit shoule be a clock ;-)it does not count days, but i think you'll get the idea :-)*/wakeup interrupt (TIMERA0_VECTOR) INT_TimerA_CCR0(void) {    CCR0 += ONESECOND;                  //setup next irq    if (++s > 59) {                     //count seconds, up to one minute        s = 0;                          //reset seconds and ...        if (++m > 59) {                 //count miutes, up to one hour            m = 0;                      //reset minutes and ...            if (++h > 23) {             //cound hours, up to one day                h = 0;                  //reset hours and ...                //++day ...             //don't do anything, could count days here            }        }    }}/**Main function with init an an endless loop that is synced with theinterrupts trough the lowpower mode.*/int main(void) {    int i = 0;    WDTCTL = WDTCTL_INIT;               //Init watchdog timer    P1OUT  = P1OUT_INIT;                //Init output data of port1    P2OUT  = P2OUT_INIT;                //Init output data of port2    P1SEL  = P1SEL_INIT;                //Select port or module -function on port1    P2SEL  = P2SEL_INIT;                //Select port or module -function on port2    P1DIR  = P1DIR_INIT;                //Init port direction register of port1    P2DIR  = P2DIR_INIT;                //Init port direction register of port2    P1IES  = P1IES_INIT;                //init port interrupts    P2IES  = P2IES_INIT;    P1IE   = P1IE_INIT;    P2IE   = P2IE_INIT;    BCSCTL1 |= DIVA0 | DIVA1;           //setup divider for RTC    TACTL  = TACTL_INIT;                //setup timer (still stopped)    CCR0   = ONESECOND;                 //setup first RTC irq    CCTL0  = CCIE;                      //enable compare interrupts    CCTL1  = 0;                         //the other modules are not used    CCTL2  = 0;                         //...    TACTL  |= MC1;                      //start timer    eint();                             //enable interrupts    P2OUT |= LED;                       //light LED during init    lcdOn();                            //reset sequence    lcdInit();                          //setup LCD modes    lcdDownloadFont(lcdfont, sizeof(lcdfont));    P2OUT &= ~LED;                      //switch off LED    puts("Hi, I'm a clock");            //say hello    while (1) {                         //main loop, never ends...        lcdInstr(LCD_LINE2);        //show the clock        //as we are synced with the interrupt, its save to read h,m,s        //otherwise a dint..eint around the following line would be        //very helpful to prevent bogus values        printf("%02d:%02d:%02d", h, m, s);        //now show the bargraph. it hasn't to do much with a clock        //but we want to show the feature here...        lcdInstr(LCD_LINE2+15);        putchar(i);        if (++i >= 8) i = 0;            //lets show all 8 downloadable chars        LPM0;                           //sync, wakeup by irq    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -