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

📄 lcd.c

📁 基于MSP430单片机的LCD显示电流表程序!
💻 C
字号:
////////////the clock sub made by zhh on 2004-08-01/////////////////////////
#include  <msp430x41x.h>
unsigned char Second;
unsigned char Minute;
unsigned char Hour;
unsigned char LCD[10][4] = {
0x11,0x11,0x11,0x00,  /* "0" LCD segments a+b+c+d+e+f */
0x10,0x01,0x00,0x00,  /* "1" */
0x11,0x10,0x01,0x01,  /* "2" */
0x11,0x11,0x00,0x01,  /* "3" */
0x10,0x01,0x10,0x01,  /* "4" */
0x01,0x11,0x10,0x01,  /* "5" */
0x01,0x11,0x11,0x01,  /* "6" */
0x11,0x01,0x00,0x00,  /* "7" */
0x11,0x11,0x11,0x01,  /* "8" */
0x11,0x11,0x10,0x01,   /* "9" */
};
void DisplayTime(void);
void main(void)
{
 WDTCTL = WDTPW + WDTHOLD;             // Stop watchdog timer
 ////////////////////initial variable
 Second=00;
 Minute=00;
 Hour=12;
 ////////////////////initail Key
 P1SEL&=~(BIT4+BIT5);//I/O mode
 P1DIR&=~(BIT4+BIT5);//input mode
 ////////////////////initail LCD
 FLL_CTL0 |= XCAP14PF;                 // Configure load caps
 LCDCTL = LCDON + LCD4MUX + LCDP2;     // STK LCD 4Mux, S0-S17
 BTCTL = BTFRFQ1;                      // STK LCD freq 
 P5SEL = 0xFC;                         // Common and Rxx all selected
 ////////////////////initial Timer
 TACTL=TASSEL0+TACLR; //ACLK,clr TAR
 CCTL0=CCIE;          //allow CCR0 interrupt 
 CCR0=32767;          //32.768kHZ,0.5s
 TACTL|=MC0;          //Timer_A is adding mode
 _EINT();             //allow interrupt
 _BIS_SR(CPUOFF);
 _BIS_SR(SCG1);
 _BIS_SR(SCG0);       //low power LMP3
 while(1);            //stop here     
}
void DisplayTime(void)
{
 LCDMEM[0] =LCD[Minute%10][0];//S0~7:"0"
 LCDMEM[1] =LCD[Minute%10][1];//
 LCDMEM[2] =LCD[Minute%10][2];//
 LCDMEM[3] =LCD[Minute%10][3];//
 LCDMEM[4] =LCD[Minute/10][0];//S8~15:"1"
 LCDMEM[5] =LCD[Minute/10][1];//
 LCDMEM[6] =LCD[Minute/10][2];//
 LCDMEM[7] =LCD[Minute/10][3];//
 LCDMEM[7]=LCDMEM[7]|0x10;
 LCDMEM[8] =LCD[Hour%10][0];//S8~15:"1"
 LCDMEM[9] =LCD[Hour%10][1];//
 LCDMEM[10] =LCD[Hour%10][2];//
 LCDMEM[11] =LCD[Hour%10][3];//
 if(Hour/10)LCDMEM[11]=LCDMEM[11]|0x10;
}
interrupt[TIMERA0_VECTOR]void TIMER_A(void)
{
 unsigned char i;
 Second++;
 if(Second==60)
 {
  Second=0;Minute++;
  if(Minute==60)
  {
   Minute=0;Hour++;
   if(Hour==13)Hour=1;
  }
 }
 if((P1IN&BIT4)!=BIT4)
 {
  for(i=0;i<255;i++) ;
  if((P1IN&BIT4)!=BIT4)Minute++;
  if(Minute==60)Minute=0;
 }
 if((P1IN&BIT5)!=BIT5)
 {
  for(i=0;i<255;i++) ;
  if((P1IN&BIT5)!=BIT5)Hour++;
  if(Hour==13)Hour=1;
 }
 DisplayTime();
}

⌨️ 快捷键说明

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