原理图、PCB_PDF档
部分源程序预览:
- #include <msp430.h>
- #include <stdint.h>
- #include "Application\delay.h"
- #include "Application\Display.h"
- #include "Application\DS3231.h"
- #include "Application\VS10XX.h"
- #define BUTTON_PORT_DIR P2DIR
- #define BUTTON_PORT_IES P2IES
- #define BUTTON_PORT_IFG P2IFG
- #define BUTTON_PORT_IE P2IE
- #define BUTTON_FUNC BIT2
- #define BUTTON_SET BIT3
- #define BUTTON_UP BIT1
- #define BUTTON_DOWN BIT0
- #define DISP_REFRESH_GAP 60000
- #define PARA_REFRESH_GAP 60000
- /* Function indication variable
- * 1: Emoji Display
- * 2: Time Display
- * 3: Temp Display
- */
- uint8_t FUNC_SWITCH = 1;
- #define FUNC_MAX 5
- //Define display order
- #define DISP_ORDER_EMOJI 2//Display Emoji
- #define DISP_ORDER_TIME_TEMP 3//Display time and temperature in turn
- #define DISP_ORDER_TIME 4//Display time
- #define DISP_ORDER_TEMP 5//Display temperature
- #define DISP_ORDER_CHS 1//Display Chinese character, rolling from right to left
- #define DISP_ORDER_SPEC 6//Display spectrum//In development
- uint8_t GLOBE_STATIC_RESET = 0;//Used to reset all static variables when function is switched and needed, especially counter variables
- //DISP_CHS clears this in display sub-function in display.c
- //Others clear this in TIMER_A0 interrupt
- uint8_t DISP_EMOJI_NOW = 0;
- uint8_t DISP_EMOJI_NEXT = 0;
- #define DISP_EMOJI_MAX 21//Define maximum emoji #//XXX
- uint8_t DISP_EMOJI_TRANS_DIR = 1;
- #define DISP_EMOJI_TRANS_DIR_MAX 4
- extern uint8_t Time_Str[2][5];
- extern uint8_t Time_SetStr[6][4];
- uint8_t Time_Set = 0;
- uint8_t Time_Set_Idx = 0;
- extern int8_t Temp_Read;
- extern uint8_t Temp_Str[4];
- uint8_t Time_Temp_Idx = 0;//Index for time/temperature, 0 for time and 1 for temperature
- uint16_t Time_Temp_Cnt = 0;//Counter for time/temperature display
- #define Time_Temp_Cnt_Max 100//Set switch speed//100 equals about 6 seconds//XXX
- uint8_t DISP_CHS_IDX = 1;
- #define DISP_CHS_IDX_MAX 1//Define maximum strings in CHS STR//XXX
- /*
- * main.c
- */
- void Set_Clock(void)
- {
- volatile unsigned int i;
- BCSCTL1 |= XTS; // ACLK= LFXT1 = HF XTAL
- do
- {
- IFG1 &= ~OFIFG; // Clear OSCFault flag
- for (i = 0xFF; i > 0; i--); // Time for flag to set
- }
- while ((IFG1 & OFIFG)); // OSCFault flag still set?
- BCSCTL2 |= SELM_3; // MCLK= LFXT1 (safe)
- }
- void Set_TIMER_B(void)//TIMER_B has higher priority
- {
- WDTCTL = WDTPW + WDTHOLD; // Stop WDT
- TBCTL = TBCLR;
- TBCCTL0 = CCIE; // CCR1 interrupt enabled
- TBCCR0 = DISP_REFRESH_GAP;
- TBCTL = TBSSEL_1 + MC_1; // ACLK, upmode
- TBCTL |= TBIE;
- }
- void Set_TIMER_A(void)
- {
- WDTCTL = WDTPW + WDTHOLD; // Stop WDT
- TACTL = TACLR;
- TACCTL0 = CCIE; // CCR1 interrupt enabled
- TACCR0 = PARA_REFRESH_GAP;
- TACTL = TASSEL_1 + MC_1 + ID_3; // ACLK, upmode, devide 8
- TACTL |= TAIE;
- }
- void Set_Button_Int(void)
- {
- WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
- BUTTON_PORT_DIR &= ~(BUTTON_FUNC + BUTTON_SET + BUTTON_UP + BUTTON_DOWN);
- BUTTON_PORT_IES |= (BUTTON_FUNC + BUTTON_SET + BUTTON_UP + BUTTON_DOWN);
- BUTTON_PORT_IFG &= ~(BUTTON_FUNC + BUTTON_SET + BUTTON_UP + BUTTON_DOWN);
- BUTTON_PORT_IE |= (BUTTON_FUNC + BUTTON_SET + BUTTON_UP + BUTTON_DOWN);
- }
- void main(void) {
- // uint16_t temp=0;
- WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
- P5DIR |= BIT5;//XXX
- Set_Clock();
- Set_TIMER_B();
- Set_TIMER_A();
- Set_Button_Int();
- Disp_Port_Init();
- I2C_Port_Init();
- _BIS_SR(GIE);
- while(1)
- {
- }
- }
- // Timer B0 interrupt service routine
- // Used as display timer
- #pragma vector=TIMERB0_VECTOR
- __interrupt void Timer_B (void)
- {
- TBCTL &= ~TBIFG;
- TBCCTL0 &= ~CCIFG;
- P5OUT |= BIT5;//XXX
- switch(FUNC_SWITCH)
- {
- case DISP_ORDER_EMOJI://Display Emoji
- Disp_Emoji(DISP_EMOJI_NOW);
- break;
- case DISP_ORDER_TIME://Display and adjust Time
- if(Time_Set == 0)
- {
- Disp_Char_8(1, 1, Time_Str[0][0]);
- Disp_Char_8(1, 2, Time_Str[0][1]);
- Disp_Icon_8(1, 3, 0);
- Disp_Char_8(1, 4, Time_Str[0][3]);
- Disp_Char_8(1, 5, Time_Str[0][4]);
- Disp_Char_8(2, 1, Time_Str[1][0]);
- Disp_Char_8(2, 2, Time_Str[1][1]);
- Disp_Char_8(2, 3, Time_Str[1][2]);
- Disp_Char_8(2, 4, Time_Str[1][3]);
- Disp_Char_8(2, 5, Time_Str[1][4]);
- }
- else
- {
- switch(Time_Set_Idx)
- {
- case 0:
- Disp_Char_8(1, 1, 'S');
- Disp_Char_8(1, 2, 'E');
- Disp_Char_8(1, 3, 'T');
- Disp_Char_8(2, 2, 'T');
- Disp_Char_8(2, 3, 'I');
- Disp_Char_8(2, 4, 'M');
- Disp_Char_8(2, 5, 'E');
- break;
- case 1:
- Disp_Char_8(1, 1, 'Y');
- Disp_Char_8(1, 2, 'E');
- Disp_Char_8(1, 3, 'A');
- Disp_Char_8(1, 4, 'R');
- Disp_Char_8(2, 2, Time_SetStr[0][0]);
- Disp_Char_8(2, 3, Time_SetStr[0][1]);
- Disp_Char_8(2, 4, Time_SetStr[0][2]);
- Disp_Char_8(2, 5, Time_SetStr[0][3]);
- break;
- case 2:
- Disp_Char_8(1, 1, 'M');
- Disp_Char_8(1, 2, 'O');
- Disp_Char_8(1, 3, 'N');
- Disp_Char_8(1, 4, 'T');
- Disp_Char_8(1, 5, 'H');
- Disp_Char_8(2, 4, Time_SetStr[1][2]);
- Disp_Char_8(2, 5, Time_SetStr[1][3]);
- break;
- case 3:
- Disp_Char_8(1, 1, 'D');
- Disp_Char_8(1, 2, 'A');
- Disp_Char_8(1, 3, 'Y');
- Disp_Char_8(2, 4, Time_SetStr[2][2]);
- Disp_Char_8(2, 5, Time_SetStr[2][3]);
- break;
- case 4:
- Disp_Char_8(1, 1, 'H');
- Disp_Char_8(1, 2, 'O');
- Disp_Char_8(1, 3, 'U');
- Disp_Char_8(1, 4, 'R');
- Disp_Char_8(2, 4, Time_SetStr[3][2]);
- Disp_Char_8(2, 5, Time_SetStr[3][3]);
- break;
- case 5:
- Disp_Char_8(1, 1, 'M');
- Disp_Char_8(1, 2, 'I');
- Disp_Char_8(1, 3, 'N');
- Disp_Char_8(2, 4, Time_SetStr[4][2]);
- Disp_Char_8(2, 5, Time_SetStr[4][3]);
- break;
- case 6:
- Disp_Char_8(1, 1, 'S');
- Disp_Char_8(1, 2, 'E');
- Disp_Char_8(1, 3, 'C');
- Disp_Char_8(2, 4, Time_SetStr[5][2]);
- Disp_Char_8(2, 5, Time_SetStr[5][3]);
- break;
- default:
- break;
- }
- }
- break;
- case DISP_ORDER_TEMP://Display Temperature
- Disp_Char_16(1, Temp_Str[0]);
- Disp_Char_16(2, Temp_Str[1]);
- Disp_Char_16(3, Temp_Str[2]);
- Disp_Icon_16(4, 0);
- break;
- case DISP_ORDER_TIME_TEMP://Display time and temperature in turn
- if(Time_Temp_Idx == 0)
- {
- Disp_Char_8(1, 1, Time_Str[0][0]);
- Disp_Char_8(1, 2, Time_Str[0][1]);
- Disp_Icon_8(1, 3, 0);
- Disp_Char_8(1, 4, Time_Str[0][3]);
- Disp_Char_8(1, 5, Time_Str[0][4]);
- Disp_Char_8(2, 1, Time_Str[1][0]);
- Disp_Char_8(2, 2, Time_Str[1][1]);
- Disp_Char_8(2, 3, Time_Str[1][2]);
- Disp_Char_8(2, 4, Time_Str[1][3]);
- Disp_Char_8(2, 5, Time_Str[1][4]);
- }
- else
- {
- Disp_Char_16(1, Temp_Str[0]);
- Disp_Char_16(2, Temp_Str[1]);
- Disp_Char_16(3, Temp_Str[2]);
- Disp_Icon_16(4, 0);
- }
- break;
- case DISP_ORDER_CHS://Display Chinese Character and string
- Disp_Char_Chs_16(DISP_CHS_IDX);
- break;
- case DISP_ORDER_SPEC://Display Spectrum
- //Refresh spectrum display here
- break;
- default:
- break;
- }
- P5OUT &= ~BIT5;//XXX
- }
- // Timer A0 interrupt service routine
- // Used as other task timer, e.g. read DS3231
- #pragma vector=TIMERA0_VECTOR
- __interrupt void Timer_A (void)
- {
- TACTL &= ~TAIFG;
- TACCTL0 &= ~CCIFG;
- P5OUT |= BIT5;//XXX
- switch(FUNC_SWITCH)
- {
- case DISP_ORDER_EMOJI://Display Emoji
- if(GLOBE_STATIC_RESET == 1)
- GLOBE_STATIC_RESET = 0;
- break;
- case DISP_ORDER_TIME://Display and adjust Time
- if(GLOBE_STATIC_RESET == 1)
- GLOBE_STATIC_RESET = 0;
- if(Time_Set == 0)
- DS3231_Read_Time_to_Str();
- else
- DS3231_Time_to_Str();
- break;
- case DISP_ORDER_TEMP://Display Temperature
- if(GLOBE_STATIC_RESET == 1)
- GLOBE_STATIC_RESET = 0;
- Temp_Read = DS3231_Read_Temp();
- DS3231_Temp_to_Str(Temp_Read);
- break;
- case DISP_ORDER_TIME_TEMP://Display time and temperature in turn
- if(GLOBE_STATIC_RESET == 1)
- {
- GLOBE_STATIC_RESET = 0;
- Time_Temp_Idx = 0;
- }
- if(Time_Temp_Idx == 0)
- {
- DS3231_Read_Time_to_Str();
- Time_Temp_Cnt++;
- }
- else
- {
- Temp_Read = DS3231_Read_Temp();
- DS3231_Temp_to_Str(Temp_Read);
- Time_Temp_Cnt++;
- }
- if(Time_Temp_Cnt > Time_Temp_Cnt_Max)
- {
- Time_Temp_Cnt = 0;
- Time_Temp_Idx = 1 - Time_Temp_Idx;
- }
- break;
- case DISP_ORDER_CHS://Display Chinese Character
- break;
- case DISP_ORDER_SPEC://Display Spectrum
- if(GLOBE_STATIC_RESET == 1)
- GLOBE_STATIC_RESET = 0;
- //Read VS10XX data here
- break;
- default:
- break;
- }
- P5OUT &= ~BIT5;//XXX
- }
- // Port 2 interrupt service routine
- #pragma vector=PORT2_VECTOR
- __interrupt void Port_2(void)
- {
- if(BUTTON_PORT_IFG & BUTTON_DOWN)
- {
- switch(FUNC_SWITCH)
- {
- case DISP_ORDER_EMOJI://Display Emoji
- DISP_EMOJI_NEXT = DISP_EMOJI_NOW + 1;
- if(DISP_EMOJI_NEXT > DISP_EMOJI_MAX)
- DISP_EMOJI_NEXT = 0;
- Disp_Emoji_Trans(DISP_EMOJI_NOW, DISP_EMOJI_NEXT, DISP_EMOJI_TRANS_DIR);
- DISP_EMOJI_NOW = DISP_EMOJI_NEXT;
- break;
- case DISP_ORDER_TIME://Display and adjust Time
- if(Time_Set == 1)
- {
- switch(Time_Set_Idx)
- {
- case 1:
- Time_SetVal.time_year--;
- if(Time_SetVal.time_year < 2010)
- Time_SetVal.time_year = 2099;
- break;
- case 2:
- Time_SetVal.time_mon--;
- if(Time_SetVal.time_mon < 1)
- Time_SetVal.time_mon = 12;
- break;
- case 3:
- Time_SetVal.time_day--;
- if((Time_SetVal.time_mon == 1) || (Time_SetVal.time_mon == 3) || (Time_SetVal.time_mon == 5) || (Time_SetVal.time_mon == 7) || \
- (Time_SetVal.time_mon == 8) || (Time_SetVal.time_mon == 10) || (Time_SetVal.time_mon == 12))
- {
- if(Time_SetVal.time_day < 1)
- Time_SetVal.time_day = 31;
- }
- else if((Time_SetVal.time_mon == 4) || (Time_SetVal.time_mon == 6) || (Time_SetVal.time_mon == 9) || (Time_SetVal.time_mon == 11))
- {
- if(Time_SetVal.time_day < 1)
- Time_SetVal.time_day = 30;
- }
- else if(DS3231_Check_Leapyear(Time_SetVal.time_year))
- {
- if(Time_SetVal.time_day < 1)
- Time_SetVal.time_day = 29;
- }
- else
- {
- if(Time_SetVal.time_day < 1)
- Time_SetVal.time_day = 28;
- }
- break;
- case 4:
- Time_SetVal.time_hour--;
- if(Time_SetVal.time_hour >= 0xfe)
- Time_SetVal.time_hour = 23;
- break;
- case 5:
- Time_SetVal.time_min--;
- if(Time_SetVal.time_min >= 0xfe)
- Time_SetVal.time_min = 59;
- break;
- case 6:
- Time_SetVal.time_sec--;
- if(Time_SetVal.time_sec >= 0xfe)
- Time_SetVal.time_sec = 59;
- break;
- default:
- break;
- }
- }
- break;
- case DISP_ORDER_TEMP://Display Temperature
- break;
- case DISP_ORDER_TIME_TEMP://Display time and temperature in turn
- break;
- case DISP_ORDER_CHS://Display Chinese Character
- DISP_CHS_IDX--;
- if(DISP_CHS_IDX < 1)
- DISP_CHS_IDX = DISP_CHS_IDX_MAX;
- break;
- case DISP_ORDER_SPEC://Display Spectrum
- break;
- default:
- break;
- }
- }
- if(BUTTON_PORT_IFG & BUTTON_UP)
- {
- switch(FUNC_SWITCH)
- {
- case DISP_ORDER_EMOJI://Display Emoji
- DISP_EMOJI_NEXT = DISP_EMOJI_NOW - 1;
- if(DISP_EMOJI_NEXT == 0xff)
- DISP_EMOJI_NEXT = DISP_EMOJI_MAX;
- Disp_Emoji_Trans(DISP_EMOJI_NOW, DISP_EMOJI_NEXT, DISP_EMOJI_TRANS_DIR);
- DISP_EMOJI_NOW = DISP_EMOJI_NEXT;
- break;
- case DISP_ORDER_TIME://Display and adjust Time
- if(Time_Set == 1)
- {
- switch(Time_Set_Idx)
- {
- case 1:
- Time_SetVal.time_year++;
- if(Time_SetVal.time_year > 2099)
- Time_SetVal.time_year = 2010;
- break;
- case 2:
- Time_SetVal.time_mon++;
- if(Time_SetVal.time_mon > 12)
- Time_SetVal.time_mon = 1;
- break;
- case 3:
- Time_SetVal.time_day++;
- if((Time_SetVal.time_mon == 1) || (Time_SetVal.time_mon == 3) || (Time_SetVal.time_mon == 5) || (Time_SetVal.time_mon == 7) || \
- (Time_SetVal.time_mon == 8) || (Time_SetVal.time_mon == 10) || (Time_SetVal.time_mon == 12))
- {
- if(Time_SetVal.time_day > 31)
- Time_SetVal.time_day = 1;
- }
- else if((Time_SetVal.time_mon == 4) || (Time_SetVal.time_mon == 6) || (Time_SetVal.time_mon == 9) || (Time_SetVal.time_mon == 11))
- {
- if(Time_SetVal.time_day > 30)
- Time_SetVal.time_day = 1;
- }
- else if(DS3231_Check_Leapyear(Time_SetVal.time_year))
- {
- if(Time_SetVal.time_day > 29)
- Time_SetVal.time_day = 1;
- }
- else
- {
- if(Time_SetVal.time_day > 28)
- Time_SetVal.time_day = 1;
- }
- break;
- case 4:
- Time_SetVal.time_hour++;
- if(Time_SetVal.time_hour > 23)
- Time_SetVal.time_hour = 0;
- break;
- case 5:
- Time_SetVal.time_min++;
- if(Time_SetVal.time_min > 59)
- Time_SetVal.time_min = 0;
- break;
- case 6:
- Time_SetVal.time_sec++;
- if(Time_SetVal.time_sec > 59)
- Time_SetVal.time_sec = 0;
- break;
- default:
- break;
- }
- }
- break;
- case DISP_ORDER_TEMP://Display Temperature
- break;
- case DISP_ORDER_TIME_TEMP://Display time and temperature in turn
- break;
- case DISP_ORDER_CHS://Display Chinese Character
- DISP_CHS_IDX++;
- if(DISP_CHS_IDX > DISP_CHS_IDX_MAX)
- DISP_CHS_IDX = 1;
- break;
- case DISP_ORDER_SPEC://Display Spectrum
- break;
- default:
- break;
- }
- }
- if(BUTTON_PORT_IFG & BUTTON_FUNC)
- {
- FUNC_SWITCH++;
- GLOBE_STATIC_RESET = 1;
- if(FUNC_SWITCH > FUNC_MAX)
- FUNC_SWITCH = 1;
- {
- Time_Set = 0;
- Time_Set_Idx = 0;//Press FUNC while adjusting time will discard time adjustment
- }
- }
- if(BUTTON_PORT_IFG & BUTTON_SET)
- {
- switch(FUNC_SWITCH)
- {
- case DISP_ORDER_EMOJI://Display Emoji
- DISP_EMOJI_TRANS_DIR++;
- if(DISP_EMOJI_TRANS_DIR > DISP_EMOJI_TRANS_DIR_MAX)
- DISP_EMOJI_TRANS_DIR = 1;
- break;
- case DISP_ORDER_TIME://Display and adjust Time
- if(Time_Set == 0)
- {
- Time_Set = 1;
- Time_SetVal.time_day = Time_Read.time_day;
- Time_SetVal.time_hour = Time_Read.time_hour;
- Time_SetVal.time_hour_am_pm = Time_Read.time_hour_am_pm;
- Time_SetVal.time_hour_format = Time_Read.time_hour_format;
- Time_SetVal.time_min = Time_Read.time_min;
- Time_SetVal.time_mon = Time_Read.time_mon;
- Time_SetVal.time_sec = Time_Read.time_sec;
- Time_SetVal.time_year = Time_Read.time_year;
- }
- else
- {
- Time_Set_Idx++;
- if(Time_Set_Idx > 6)
- {
- Time_Set = 0;
- Time_Set_Idx = 0;
- DS3231_Write_Time();//Save time adjustment here
- DS3231_Read_Time_to_Str();//Refresh Time_Read variable
- }
- }
- break;
- case DISP_ORDER_TEMP://Display Temperature
- break;
- case DISP_ORDER_TIME_TEMP://Display time and temperature in turn
- break;
- case DISP_ORDER_CHS://Display Chinese Character
- break;
- case DISP_ORDER_SPEC://Display Spectrum
- break;
- default:
- break;
- }
- }
- BUTTON_PORT_IFG = 0x00;
- }
复制代码
程序和原理图下载:
原理图、PCB_PDF档.zip
(756.49 KB, 下载次数: 9)
Program.zip
(37.83 KB, 下载次数: 8)
|