关闭

关于控制液晶显示的C程序和液晶代码修改问题??

1300人阅读 评论(0) 收藏 举报

//谁把以下程序稍做修改,使其不显示公司徽标,谢谢了!!

/*****************************************************************************
  MSP430f1132 for CHUANG SHI JI DIAN YA LI BIAO   0-25Mpa
  Version: 1.0
  Author : ancn wang
  E-mail : ancn-wang@163.com
  Date   : 2004-12-25
  Old Version : None
  Data        : None
  Including functions:
  Please consult the file of includes.h
  Built with IAR Embedded Workbench Version: 3.10A                          */
//*****************************************************************************
#include <msp430x11x2.h>
#define uint   unsigned int             // 1 byte (0--255)
#define uchar  unsigned char            // 2 bytes(0--65536)
#define ulong  unsigned  long           // 4 bytes(0--4294967295)
//*****************************************************************************
#define AA   0x01                       //LCD SEG 'A' 
#define AB   0x02                       //LCD SEG 'B'
#define AC   0x04                       //LCD SEG 'C'
#define AD   0x80                       //LCD SEG 'D'
#define AE   0x40                       //LCD SEG 'E'
#define AF   0x10                       //LCD SEG 'F'
#define AG   0x20                       //LCD SEG 'G'
#define ADP  0x08                       //LCD SEG 'DP'
#define LCDCS_H  P1OUT |=  BIT3         //LCD_CS=1 P13
#define LCDCS_L  P1OUT &= ~BIT3         //LCD_CS=0
#define LCDWR_H  P2OUT |=  BIT1         //LCD_WR=1 P21
#define LCDWR_L  P2OUT &= ~BIT1         //LCD_WR=0
#define LCDDI_H  P2OUT |=  BIT2         //LCD_DI=1 P22
#define LCDDI_L  P2OUT &= ~BIT2         //LCD_DI=0
#define KJC      P2OUT |=  BIT5         //LED-DENG P25
#define TJC      P2OUT &= ~BIT5         //LED-DENG P25
#define KSET     BIT0                   //P10 = SET
#define KMOV     BIT1                   //P12 = MOV
#define KADD     BIT2                   //P11 = ADD
#define adctime  8                      //to adc10 conversion times
#define flash_a  0x1080                 //Flash segment A
#define flash_b  0x1000                 //Flash segment B
//*****************************************************************************
uint Del_max_min (uint *p,uchar i);                   //FOR DEL MAX&MIN
void LCD_INI (void);                                  //LCD SETUP
void LCD_DIS (void);                                  //DISPLAY LCDMEM[]
void Display_mod (uchar i);                           //TO SHOW SETUP SYSTEM
void WrByte_bit7 (unsigned char WriteD);              //writebyte for DGM0416 ini,bit7 is first
void WrByte_bit0 (unsigned char WriteData);           //writebyte for DGM0416 display,bit0 is first
void startadc10 (void);                               //start adc10
void JCYL (void);                                     //to cover adc one times
void Sampling_save (void);                            //for sampling_save for meterage
void Iint_Port1(void);                                //FOR KADD IINT ISR
void ram_flash (uint *ram,uint *flash,uchar count);   //copy ram count words to flash
void flash_ram (uint *flash,uint *ram,uchar count);   //copy flash to ram
void delay (unsigned char q);                         //short time delay
void delay_l (unsigned int q);                        //long time delay
//*****************************************************************************
uint  adcout[adctime];                                  //adc10 conversion result
uint  adresult = 0;                                     //adc result
uint  ad_value = 0;                                     //zan cun
uint  duram [7];                                        // flash to ram
uchar MAINV;                                            // for key setup
ulong ylzhi = 0;                                        // fro jisuan+_result
uint  yy = 0;
uchar KEY_Value = 0;                                    //key value
uchar SET_Time = 0;                                     //kset time
uchar SET_Value[4];                   // For the Setting value register and for show value on LCD
uchar LCDMEM[] = {0,0,0,0,4};                           //1000,100,10,1,'.',FOR BEJINGQINGYUN-LCM046
const uchar LCDINI[]={0X02,0X06,0X52};                  //FOR SETUP LCD
const uint  YALI[]={0,200,500,1000,1500,2000,2500};     //FOR yalileijia
const uchar DISTAB[] = {AA+AB+AC+AD+AE+AF,AB+AC,AA+AB+AD+AE+AG,AA+AB+AC+AD+AG,        //0,1,2,3
             AB+AC+AF+AG,AA+AC+AD+AF+AG,AA+AC+AD+AE+AF+AG,AA+AB+AC,                   //4,5,6,7
             AA+AB+AC+AD+AE+AF+AG,AA+AB+AC+AD+AF+AG,AA+AB+AC+AE+AF+AG,AC+AD+AE+AF+AG, //8,9,A,b
             AA+AD+AE+AF, AB+AC+AD+AE+AG, AA+AD+AE+AF+AG,AA+AE+AF+AG,                 //c,d,E,F
             AA+AB+AC+AD+AE+AF+ADP,AB+AC+ADP,AA+AB+AD+AE+AG+ADP, AA+AB+AC+AD+AG+ADP,  //0.,1.,2.,3.
             AB+AC+AF+AG+ADP,AA+AC+AD+AF+AG+ADP,AA+AC+AD+AE+AF+AG+ADP,AA+AB+AC+ADP,   //4.,5.,6.,7.
             AA+AB+AC+AD+AE+AF+AG+ADP,AA+AB+AC+AD+AF+AG+ADP,AB+AC+AE+AF+AG,AD+AE+AF,  //8.,9.H 1AH,L 1BH
             AC+AD+AE+AG,AB+AE+AF+AG,AG,0x0,                                          // 1CH 'o', 1DH 'r',1eh '-',1fh 'kong'
             AA+AB+AC+AE+AF};                                                         //20h 'n',
//*****************************************************************************
void main(void)

  BCSCTL1 |= DIVA_2;                   // Aclk = 32768/4
  WDTCTL = WDT_ARST_1000;              //Set Watchdog Timer RST to 4000ms
  _EINT();
  TACTL = TASSEL_1 + TACLR + MC0;      // ACLK, contmode ,CLR TAR
  CCTL0 = CCIE;                        // CCR0 interrupt enabled
  CCR0 = 24576;                        // ACLK IN,ABOUT 3S 
  delay_l (65535);                     //delay time
  P1DIR = BIT3 ;                       //FOR  LCD & key
  P2DIR |= BIT1+BIT2+BIT5;             //FOR  LCD & KJC
  TJC;
  LCD_INI ();                          //LCD-SETUP
  Display_mod(0);                      //display show
  flash_ram ((uint*)flash_a,(uint*)duram,7);
  while (1)
 { 
    MAINV = 50;
    while (MAINV != 0 || SET_Time != 0)
  {  
    if((P1IN & (KSET+KMOV+KADD)) != (KSET+KMOV+KADD))  // To find one key pressed 
      {
        delay_l (28000);                          // To escape the interfere of key's jumping
  if((P1IN & (KSET+KMOV+KADD)) != (KSET+KMOV+KADD)) // To affirm the key pressed
   {
     switch(P1IN & (KSET+KMOV+KADD))
      {
       case (KMOV+KADD) : KEY_Value = KSET;     break;  // SET
       case (KSET+KADD) : KEY_Value = KMOV;     break;  // MOV
       case (KSET+KMOV) : KEY_Value = KADD;     break;  // ADD
       default : KEY_Value = 0;     break;
       }
     delay (255);
          }
        else KEY_Value = 0;
      }
    else
        {
         MAINV--;
         KEY_Value = 0;
        }
    if(KEY_Value != 0)
      {
       WDTCTL = WDTPW + WDTHOLD;                          // Stop WDT
       CCTL0 &= ~CCIE;                                    // CCR0 interrupt is closed
       if(KEY_Value == KSET)
         {
               SET_Time++;
           if (SET_Time > 9)
               SET_Time = 0;
           else  {
             switch(SET_Time)                                             //displaymode for set
               {
                case 1 : Display_mod (1);                              //'-cd-'
                         SET_Value[0] = SET_Value[1] = SET_Value[2] = SET_Value[3] = 0;
                  delay_l (65535);      // For user have enough time to reaction
                 break;  
                case 2 : if(SET_Value[0]==7&&SET_Value[1]==2&&SET_Value[2]==5&&SET_Value[3]==0) //the word is key'7250'
                    {
                     Display_mod (2);                  // ' 0.00mpa'
                      delay_l (65535);                            
                    }
                         else
                           {
                  WDTCTL = WDT_ARST_1000; 
                  CCTL0 = CCIE;                        // CCR0 interrupt enabled                      
                  SET_Time = 0; 
                  MAINV=0; 
                  }     
                         break;
                case 3 :
                         Sampling_save();   
                         ad_value = adresult;                      
                         duram[0] = adresult;              //0.00 zhi
                         delay_l (65535);
                         ram_flash ((uint*)duram,(uint *)flash_a,7);
                  Display_mod (3);                  // ' 2.00mpa'                 
                  break;
                case 4 :
                         Sampling_save ();                        
                         duram[1] = (adresult - ad_value); //2.00 zhi
                         ad_value = adresult;
                         delay_l (65535);
                         ram_flash ((uint*)duram,(uint *)flash_a,7);
                         Display_mod (4);                  // ' 5.00mpa'
                 break;
                case 5 :
                         Sampling_save ();
                         duram[2] = (adresult - ad_value); //5.00 zhi
                         ad_value = adresult;                        
                         delay_l (65535);
                         ram_flash ((uint*)duram,(uint *)flash_a,7);
                  Display_mod (5);                  // '10.00mpa'
                 break;
                case 6 :
                         Sampling_save ();   
                         duram[3] = (adresult -ad_value); //10.00 zhi     
                         ad_value = adresult;                                   
                         delay_l (65535);
                         ram_flash ((uint*)duram,(uint *)flash_a,7);
                         Display_mod (6);                  // '20.00mpa'
                  break;                
                case 7 :
                         Sampling_save ();  
                         duram[4] = (adresult -ad_value); //20.00 zhi       
                         ad_value = adresult;             
                        delay_l (65535);
                         ram_flash ((uint*)duram,(uint *)flash_a,7);
                         Display_mod (7);                  // '30.00mpa'
                 break;
                case 8 : 
                         Sampling_save ();
                         duram[5] = (adresult - ad_value); //30.00 zhi        
                         ad_value = adresult;                
                         delay_l (65535);
                         ram_flash ((uint*)duram,(uint *)flash_a,7);
                         Display_mod (8);                  // '40.00mpa'
                  break;
                 case 9 : 
                         Sampling_save ();  
                         duram[6] = (adresult - ad_value); //40.00 zhi      
                         ad_value = adresult;           
                         delay_l (65535);
                         ram_flash ((uint*)duram,(uint *)flash_a,7);
                  WDTCTL = WDT_ARST_1000;        
                  CCTL0 = CCIE;                        // CCR0 interrupt enabled               
                  SET_Time = 0; 
                  MAINV=0;
                  break;
                default:
                         WDTCTL = WDT_ARST_1000;
                         CCTL0 = CCIE;                        // CCR0 interrupt enabled
                         SET_Time = 0;
                         MAINV=0;
                         break;
               }
           }
         }
       else
       {
        if(((KEY_Value == KADD) || (KEY_Value == KMOV)) && (SET_Time == 1))
         {
          if(KEY_Value == KADD && SET_Time == 1) // The KEY_ADD pressed
            {
             if  (SET_Value[3] <= 8)
                  SET_Value[3]++;
             else SET_Value[3] = 0;          // "0"
            }
          else if(KEY_Value == KMOV && SET_Time == 1) // The KEY_MOV pressed
            {
             SET_Value[0] = SET_Value[1];
             SET_Value[1] = SET_Value[2];
             SET_Value[2] = SET_Value[3];
             SET_Value[3] = 0;
            }
         LCDMEM[0] = DISTAB[SET_Value[0]];
         LCDMEM[1] = DISTAB[SET_Value[1]];
         LCDMEM[2] = DISTAB[SET_Value[2]];
         LCDMEM[3] = DISTAB[SET_Value[3]];
         LCD_DIS();
         }
       // To deal with the KEY of "Alarm_Cancel" pressed
        if((KEY_Value == KMOV) && SET_Time == 0)
         {
          Display_mod (11);                  // ' -00-'
          delay_l (20000); 
          Sampling_save ();
          if ((adresult >(duram[0]-20)) && (adresult <(duram[0]+20)))// duram-15>adc>duram+15
          {
           duram[0] = adresult;             //0.00 zhi                       
           ram_flash ((uint*)duram,(uint *)flash_a,7);
          }
          else
          {
          Display_mod (14);                  // ' eero'
          delay_l (20000); 
          }
          WDTCTL = WDT_ARST_1000;       
          CCTL0 = CCIE;                     // CCR0 interrupt enabled              
          SET_Time = 0; 
          MAINV=0; 
         }
        if((KEY_Value == KADD) && SET_Time == 0)
         {
          Display_mod (13);                  // ' -OFF'
          WDTCTL=WDTPW+WDTHOLD;
          CCTL0 &= ~CCIE;                    // CCR0 interrupt is closed
          delay_l (65535);                   //delay time
          delay_l (65535);                   //delay time
          Iint_Port1();                      //kadd to iint isr         
          _BIS_SR(LPM3_bits + GIE);          //Enter LPM0 / interrupt
          _NOP();
          Display_mod(12);                   //-ON-
          P1IE &= ~KADD;                     // CLOSE ISR FOR KADD
          WDTCTL = WDT_ARST_1000;   
          CCTL0 = CCIE;                     // CCR0 interrupt enabled
          SET_Time = 0; 
          MAINV=0; 
         }
       }   
    }
  }
   _BIS_SR(LPM3_bits + GIE);            //Enter LPM0 / interrupt
   _NOP();                              //Required only for C-spy
 }
}
/*-------------------------------------------------------------------
Name :void LCD_INI(void)
Description: DGM0416 SETUP
Input : None
Date  : 2004-12-01
-------------------------------------------------------------------*/  
void LCD_INI(void)
 {
    uchar b;
    LCDCS_H;            //CS=1
    LCDWR_L;            //WR=0
    LCDDI_H;            //DI=1
    delay (3);
    LCDCS_L;            //CS=0
    delay (2);
    LCDWR_H;            //WR=1
    delay (2);
    LCDWR_L;            //WR=0  DATA=1
    delay (2);
    LCDDI_L;            //DI=0 
    delay (2);
    LCDWR_H;            //WR=1
    delay (2);
    LCDWR_L;           //WR=0  DATA=0
    delay (2); 
    LCDWR_H;           //WR=1
    delay (2);
    LCDWR_L;           //WR=0  DATA=0
    for(b=0;b<3;b++)
    {
    delay (2);
    LCDDI_L;           //OUT=0
    delay(2);
    LCDWR_H;           //WR=1
    delay(2);
    LCDWR_L;           //WR=0
    delay(2);
    WrByte_bit7 (LCDINI[b]); //lcd ini
    }
    LCDCS_H;            //CS=1
    LCDDI_H;            //DI=1
 }
/*-------------------------------------------------------------------
Name :void LCD_INI(void)
Description: DGM0416 SETUP
Input : None
Date  : 2004-12-01
-------------------------------------------------------------------*/  
void LCD_DIS(void)
  {
   LCDCS_H;            //CS=1
   LCDWR_L;            //WR=0
   LCDDI_H;            //DI=1
   delay (3);
   LCDCS_L;            //CS=0
   delay (2);
   LCDWR_H;            //WR=1
   delay (2);
   LCDWR_L;            //WR=0  DATA=1
   delay (2);
   WrByte_bit7 (0X40);       //START ADDR |= 0X40
   WrByte_bit0 (LCDMEM[3]);  //1    WEI
   WrByte_bit0 (LCDMEM[2]);  //10   WEI
   WrByte_bit0 (LCDMEM[1]);  //100  WEI
   WrByte_bit0 (LCDMEM[0]);  //1000 WEI
   WrByte_bit0 (LCDMEM[4]);  //P1-P4
   delay (3);
   LCDCS_H;            //CS=1
   LCDDI_H;            //DI=1  
   LCDWR_H;            //WR=1
  }
/*-------------------------------------------------------------------
Name :void WrByte_bit7(void)
Description: LCM046 SETUP INITAB
Input : None
Output: BIT7 -> BIT6 ->... ->BIT0 ;BIT7 IS FIRST    !!!!
Date  : 2004-12-01
-------------------------------------------------------------------*/  
void WrByte_bit7 (unsigned char WriteD)
{
  unsigned char FT;
  for (FT=0; FT<8; FT++)
  {
    LCDWR_L;                           //WR=0
    delay(2);
    if ((WriteD & 0X80) == 0)          //BIT7 =0 ?
    {
      LCDDI_L;                         //DI=0
    }
    else
    {
      LCDDI_H;                         //DI=1
    }
    delay(2);
    LCDWR_H;                           //WR=1
    WriteD  <<= 1;                     //bit7 -> bit0
    delay(2); 
  }
     LCDWR_L;
}
/*-------------------------------------------------------------------
Name :void WrByte_bit0 (unsigned char WriteData)
Description: LCM046 display mem
Input : None
Output: BIT0 -> BIT1 ->... ->BIT7;BIT0 IS FIRST    !!!!
Date  : 2004-12-01
-------------------------------------------------------------------*/  
void WrByte_bit0 (unsigned char WriteData)
{
  unsigned char FT;
  for (FT=0; FT<8; FT++)
  {
    LCDWR_L;                            //WR=0
    delay(2);
    if ((WriteData & 0X01) == 0)        //BIT0 =0 ?
    {
      LCDDI_L;                          //DI=0
    }
    else
    {
      LCDDI_H;                          //DI=1
    }
    delay(2);
    LCDWR_H;                           //WR=1
    WriteData >>= 1;                   //bit0 -> bit7
    delay(2);
  }
    LCDWR_L;
 } 
/*------------------------------------------------------------------------------
Name : void Display_mod (uchar i)
Description : To display the mode at present
Input : i-- mode nuber (0--12)
Output: None
Data  : 2004-12-15
------------------------------------------------------------------------------*/
void Display_mod (uchar i)
{
 LCD_INI();
 switch(i)
   {
    case 0 : LCDMEM[0]=DISTAB[0x1a];          // 'H'
             LCDMEM[1]=DISTAB[0x1e];          // '-'
             LCDMEM[2]=DISTAB[0x1e];          // '-'
             LCDMEM[3]=DISTAB[0x1b];          // 'L'
             LCD_DIS();
             break;
    case 1 : LCDMEM[0]=DISTAB[0x1e];          // '-'
             LCDMEM[1]=DISTAB[0xc];           // 'c'
             LCDMEM[2]=DISTAB[0xd];           // 'd'
             LCDMEM[3]=DISTAB[0x1e];          // '-'
             LCD_DIS();
             break;
    case 2 : LCDMEM[0]=DISTAB[0x1f];          // ' '
             LCDMEM[1]=DISTAB[0x10];          // '0.'
             LCDMEM[2]=DISTAB[0x0];           // '0'
             LCDMEM[3]=DISTAB[0x10];          // '0'
             LCD_DIS();
             break;
    case 3 : LCDMEM[0]=DISTAB[0x1f];         // ' '
             LCDMEM[1]=DISTAB[0x12];         // '2.'
             LCDMEM[2]=DISTAB[0x0];          // '0'
             LCDMEM[3]=DISTAB[0x10];         // '0'
             LCD_DIS();
             break;
    case 4 : LCDMEM[0]=DISTAB[0x1f];         // ' '
             LCDMEM[1]=DISTAB[0x15];         // '5.'
             LCDMEM[2]=DISTAB[0x0];          // '0'
             LCDMEM[3]=DISTAB[0x10];         // '0'
             LCD_DIS();
             break;
    case 5 : LCDMEM[0]=DISTAB[0x1];          // '1'
             LCDMEM[1]=DISTAB[0x10];         // '0.'
             LCDMEM[2]=DISTAB[0x0];          // '0'
             LCDMEM[3]=DISTAB[0x10];         // '0'
             LCD_DIS();
             break;
    case 6 : LCDMEM[0]=DISTAB[0x1];          // '1'
             LCDMEM[1]=DISTAB[0x15];         // '5.'
             LCDMEM[2]=DISTAB[0x0];          // '0'
             LCDMEM[3]=DISTAB[0x10];         // '0'
             LCD_DIS();
             break;
    case 7 : LCDMEM[0]=DISTAB[0x2];          // '2'
             LCDMEM[1]=DISTAB[0x10];         // '0.'
             LCDMEM[2]=DISTAB[0x0];          // '0'
             LCDMEM[3]=DISTAB[0x10];         // '0'
             LCD_DIS();
             break;
    case 8 : LCDMEM[0]=DISTAB[0x2];          // '2'
             LCDMEM[1]=DISTAB[0x15];         // '5.'
             LCDMEM[2]=DISTAB[0x0];          // '0'
             LCDMEM[3]=DISTAB[0x10];         // '0'
             LCD_DIS();
             break;
    case 9 : LCDMEM[0]=DISTAB[0x1e];         // '-'
             LCDMEM[1]=DISTAB[0x1a];         // 'H'
             LCDMEM[2]=DISTAB[0x1a];         // 'H'
             LCDMEM[3]=DISTAB[0x1e];         // '-'
             LCD_DIS();
             break;
    case 10 :LCDMEM[0]=DISTAB[0x1e];         // '-'
             LCDMEM[1]=DISTAB[0x1b];         // 'L'
             LCDMEM[2]=DISTAB[0x1b];         // 'L'
             LCDMEM[3]=DISTAB[0x1e];         // '-'
             LCD_DIS();
             break;
    case 11 :LCDMEM[0]=DISTAB[0x1e];         // '-'
             LCDMEM[1]=DISTAB[0x0];          // '0'
             LCDMEM[2]=DISTAB[0x0];          // '0'
             LCDMEM[3]=DISTAB[0x1e];         // '-'
             LCD_DIS();
             break;        
    case 12 :LCDMEM[0]=DISTAB[0x1e];         // '-'
             LCDMEM[1]=DISTAB[0x1c];         // 'o'
             LCDMEM[2]=DISTAB[0x20];         // 'n'
             LCDMEM[3]=DISTAB[0x1e];         // '-'
             LCD_DIS();
             break;
    case 13 :LCDMEM[0]=DISTAB[0x1f];         // ' '
             LCDMEM[1]=DISTAB[0x0];          // 'o'
             LCDMEM[2]=DISTAB[0xf];          // 'f'
             LCDMEM[3]=DISTAB[0xf];          // 'f'
             LCD_DIS();
             break;
    case 14 :LCDMEM[0]=DISTAB[0xe];          // 'e'
             LCDMEM[1]=DISTAB[0xe];          // 'e'
             LCDMEM[2]=DISTAB[0x1d];         // 'r'
             LCDMEM[3]=DISTAB[0x1c];         // 'o'
             LCD_DIS();
             break;
    case 15 :LCDMEM[0]=DISTAB[0xe];          // 'e'
             LCDMEM[1]=DISTAB[0xe];          // 'e'
             LCDMEM[2]=DISTAB[0x1d];         // 'r'
             LCDMEM[3]=DISTAB[0x1c];         // 'o'
             LCD_DIS();
             break;               
    default: break;
   }
}
/*------------------------------------------------------------------------------
Name : void ram_flash (uint *ram,uint *flash,uchar count)
Description : flash wriht a word
Input : flash addr & ram addr & word count
Data  : 2004-12-12
------------------------------------------------------------------------------*/
void ram_flash (uint *ram,uint *flash,uchar count)
{
  _DINT();                                          //close inter
  FCTL1 = FWKEY + ERASE;                            // Set Erase bit
  FCTL3 = FWKEY;                                    // Clear Lock bit
  *flash = 0;                                       //erase
  FCTL1 = FWKEY + WRT;                              // Set WRT bit for write operation
  while (count)
   {
     *flash++ = *ram++;                             // copy COUNT WORDS
     count--;
    }
  FCTL1 = FWKEY;                                    // Clear WRT bit
  FCTL3 = FWKEY + LOCK;                             // Reset LOCK bit      
  _EINT(); 
}
 /*------------------------------------------------------------------------------
Name : void flash_ram (uint *flash,uint *ram,uchar count);
Description : flash copy to ram
Input : ram addr & flash addr & word count
Data  : 2004-12-12
------------------------------------------------------------------------------*/
void flash_ram (uint *flash,uint *ram,uchar count)
{
  while (count)
   {
     *ram++ = *flash++;                            // copy COUNT WORDS to ram
     count--;
    }
}
/*------------------------------------------------------------------------------
Name : void startadc10 (void)
Description : START ADC10
Input : adc10 in0
Output: adcout[]
Data  : 2004-12-11
------------------------------------------------------------------------------*/
void startadc10 (void)
{
  ADC10CTL0 &= ~ENC;                                           // close adc
  ADC10AE   = 0x01;                                            // P2.0 ADC option select
  ADC10CTL0 = SREF_2 + ADC10SHT_1 + MSC + ADC10ON + ADC10IE;   // ADC10ON, interrupt enabled
  ADC10CTL1 = INCH_0 + CONSEQ_2 + ADC10SSEL_1;                 // Repeat single channel in aclk adc10 in0
  ADC10DTC1 = adctime ;                                        // 8 conversions  
  ADC10SA = (int)adcout;                                       // adc10 result in adcout[]
  ADC10CTL0 |= ENC + ADC10SC;                                  // Sampling and conversion start
}
/*------------------------------------------------------------------------------
Name : void JCYL (void)
Description :  ADC10 sampling
Input : adc10 in0
Output: adcout[]
Data  : 2004-12-11
------------------------------------------------------------------------------*/
void JCYL (void)
{
  _EINT();                              //OPEN ISR NESTING
  KJC;
  delay_l (7000);
  startadc10 ();                        //adc10 to conversion
  _BIS_SR(LPM3_bits + GIE);             //Enter LPM0 / interrupt
  _NOP();                               //WAIT FOR ADC OVER
}
/*------------------------------------------------------------------------------
Name : void Sampling_save (void)
Description :yali Sampling to save
Input : JCYL out adresult
Output: adresult
Data  : 2004-12-11
------------------------------------------------------------------------------*/
void Sampling_save (void)
{
 uchar i;
 uint interim[6];          //zan shi cun fang adc10 de jie guo
 for (i=0;i<6;i++)
  {
   JCYL();
   interim[i] = adresult;
  }
 adresult = Del_max_min(interim,6); 
}
/*------------------------------------------------------------------------------
Name : uint Del_max_min(uint *p,uchar i)
Description : 数字滤波
Input : *p,i
Output: 平均值
Data  : 2004-12-11
------------------------------------------------------------------------------*/
uint Del_max_min(uint *p,uchar i)
{
  uchar j;
  uint  k;
  uint  *u;
  uint max ;    // the first word
  uint min ;    // the first word
  max = min = *p;
  p++;
  u = p;
  for (j=1;j<i;j++)
  {
   if(*p>max)
    {
     max = *p;
    } 
   p++;
  }
  p = u;
  for (j=1;j<i;j++)
  {
   if ( *p<min)
    {
     min = *p;
    }
    p++;
  }
  u--;
  k = 0;
  for (j=0;j<i;j++)
  {
  k += *u;
  u++;
  }
  k = (k - max - min)/(i-2);
  return ( k );
}
/*------------------------------------------------------------------------------
Name : void Iint_Port1(void)
Description : KADD TO IINT ISR
Input : uchar i
Data  : 2004-12-3
------------------------------------------------------------------------------*/
void Iint_Port1(void)
   { 
    P1DIR &= ~KADD;                         //设置为输入方向
    P1SEL &= ~KADD;                         //设置为普通I/O口功能
    P1IES |= KADD;                          //选择下降沿触发
    P1IE |= KADD;                           //打开中断允许
    P1IFG=0;                               //P1IES的切换可能使P1IFG置位,需清除
    }
/*------------------------------------------------------------------------------
Name : delay_s(uchar i)
Description : Delay time subfunction, 1 unit about 3 nops
Input : uchar i
Data  : 2004-12-3
------------------------------------------------------------------------------*/
void delay (uchar q)
{
 uchar a;
 for(a=0; a<q; a++ );

/*------------------------------------------------------------------------------
Name : void delay_l(uchar i)
Description : Delay time subfunction, 1 unit about 5ms
Input : None
Data  : 2004-12-3
------------------------------------------------------------------------------*/
void delay_l(uint q)
{
 uint  a;
 for(a=0; a<q; a++ );
}
/*-------------------------------------------------------------------
Name :void ADC10_ISR (void)
Description: adc10isr
Input : None
Date  : 2004-12-11
-------------------------------------------------------------------*/  
#pragma vector=ADC10_VECTOR
__interrupt void ADC10_ISR (void)
{  
    uchar i;
    uint *p;   
    TJC;                          // STOP JC P2.5 OUT_1
    ADC10CTL0 &= ~ENC;           
    ADC10CTL0 &= ~ADC10ON;        // STOP ADC10 TO  SAVE ON POWER
    adresult = 0;                 //clr 0
    p = adcout;                   // *p -> adcout
    for(i=adctime;i>0;i--)        //adc result to add
   {
    adresult += *p;
    p++;
   }
   LPM3_EXIT;                   //EXIT LPM3 TO AM
}
/*-------------------------------------------------------------------
Name :void P1_ISR(void)
Description: KADD
Input : None
Date  : 2004-12-11
-------------------------------------------------------------------*/  
#pragma vector=PORT1_VECTOR
__interrupt void P1_ISR(void)

    P1IFG = 0;              //多源中断,需靠软件清除P1IFG
    LPM3_EXIT;              //将CPU从睡眠模式唤醒
}
/*-------------------------------------------------------------------
Name :void P1_ISR(void)
Description: KADD
Input : None
Date  : 2004-12-11
-------------------------------------------------------------------*/
#pragma vector=TIMERA0_VECTOR
__interrupt void Timer_A (void)
{
   uchar i;
   JCYL ();  
   ylzhi = 0;
   yy = 0;
  if (adresult == 0)
     {
      Display_mod(14);                  // eero
     } 
   else if (adresult <= (duram[0]-15) && (adresult != 0))
     {
      Display_mod(10);                  // -LL-
     } 
   else if (adresult > (duram [0] + duram [1] + duram [2] + duram [3] + duram [4] + duram [5] + duram [6]))
     {
      Display_mod(9);                   // -HH-
     }  
   else if ((adresult > (duram[0]-15)) && (adresult < (duram[0]+6)))  //零点漂移
     {
      ylzhi = 0;
      Display_mod (2);
     }
   else if(adresult >= (duram[0]+6))
    {
     i=0;
     do{
        yy += duram[i];
        i++;
       }
     while((adresult-yy) > duram[i]);
     ylzhi = (ulong) (YALI[i] - YALI[i-1])*(adresult-yy)/duram[i]+YALI[i-1];
     LCDMEM[0] = ylzhi/1000;
     LCDMEM[1] = ylzhi/100%10;
     LCDMEM[2] = ylzhi/10%10;
     LCDMEM[3] = ylzhi%10; 
     if (LCDMEM[0] == 0)
     {LCDMEM[0] = 0x1f;}                 //clr wan wei 0 to 'kong'
     LCDMEM[0] = DISTAB[LCDMEM[0]];
     LCDMEM[1] = DISTAB[LCDMEM[1]+0x10]; //'.'
     LCDMEM[2] = DISTAB[LCDMEM[2]];
     LCDMEM[3] = DISTAB[LCDMEM[3]+0x10]; //mpa
     LCD_INI ();
     LCD_DIS ();
    } 
  WDTCTL = WDT_ARST_1000;      // CLR DOG
  LPM3_EXIT;                   // EXIT LPM3 TO AM
}

 

//********************************************************************************

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:1632次
    • 积分:23
    • 等级:
    • 排名:千里之外
    • 原创:1篇
    • 转载:0篇
    • 译文:0篇
    • 评论:0条
    文章存档