Weighing scale program

Publisher:chwwdchLatest update time:2018-01-30 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

#include "MSP430x22x4.h"  
#define uchar unsigned char 
#define uint  unsigned int 
#define comm  0 
#define dat   1 

#define sclk_1 P4OUT|=0x01 //sclk=1; 001----p4.0 
#define sclk_0 P4OUT&=0x06 //sclk=0; 110----p4.1 
#define std_1 P4OUT|=0x02 //std =1; 010 
#define std_0 P4OUT&=0x05 //std =0; 101 

/***********Array and variable definition*******************************/ 

uchar xian[]={ 
  "****************" 
  " M= g "   
  "The weight of this object is: " 
  "****************" 
}; 

uchar caidan1[]={"0123456789 "}; 


float ad_value,data; 
uchar ai=0; 

/*****************************Delay function********************************/ 

void delay(uchar aj) 

  while(aj--); 


void DELAY(uchar aj) 

  for(uchar ak=0;ak<500;) 
    while(aj--); 



/* 
******************************************************************************** 
*Module name: wr_ LCD definition 
*Completion date: 08-07-29 
*Modified content: none 
**************************************************************************** 
*//********Write command/data*************************************************** 
void wr_lcd (unsigned char dat_comm,unsigned char content) 

  unsigned char a,b,i,j; 
  delay (50); 
  a=content; 
    //cs_1; //P4OUT|=0x04 //cs =1; 0100 
    sclk_0; //P4OUT&=0x06 //sclk=0; 0110 
    std_0; //P4OUT&=0x05 //std =0; 0101 
    std_1; //P4OUT|=0x02 //std =1; 0010 
  for(i=0;i<5;i++) // 
  { sclk_1;sclk_0;} 
     std_0; 
     sclk_1; 
     sclk_0; 
  if(dat_comm)std_1; 

  else 
    std_0; 
  sclk_1; 
  sclk_0; 
  std_0; 
  sclk_1; 
  sclk_0; 
  for(j= 0;j<2;j++) 
  { 
    for(i=0;i<4;i++) 
    {b=a;       
      if((b&=0x80)==0) 
      {std_0;a=a<<1;} 
      else 
      {std_1;a=a<<1;} 
      sclk_1;sclk_0; 
    } 
    std_0; 
    for(i=0;i<4;i++) 
    { sclk_1;sclk_0;} 
  } 

/************************************************************************************ 
*Module name: Initialization definition 
*Completion date: 08-7-29 
*Modified content: none 
**************************************************************************** 
*/ 
void init_lcd (void) 

  wr_lcd (comm,0x30); /*30---Basic instruction action*/    
  wr_lcd (comm,0x01); /*Clear screen, address pointer points to 00H*/ 
  delay (100); 
  wr_lcd (comm,0x06); /*cursor movement direction*/ 
  wr_lcd (comm,0x0c); /*turn on display, turn off cursor*/ 


/* 
******************************************************************************** 
*Module Name: Clear DDRAM definition 
*Completion date: 08-7-29 
*Modification content: none 
******************************************************************************** 
*/ 
void clrram (void) 

  wr_lcd (comm,0x30); 
  wr_lcd (comm,0x01); 
  delay (180); 


/* 
************************************************************************************ 
*Module Name: Display Chinese characters or character definition 
*Completion date: 08-7-29 
*Modification content: none 
******************************************************************************** 
*/ 
void chn_disp(unsigned char *chn) 

  unsigned char i; 
  wr_lcd (comm,0x30); 
  wr_lcd (comm,0x80); 
   
  for (i=0;i<64;i++) 
    wr_lcd (dat,chn[i]); 


//******************lcd_mesg fixed-point display********************************** 
void lcd_mesg(uint gao,uchar p,uch ar q) 

  uint adder1,adder2,adder3,adder4; 
  adder1=gao/1000,gao=gao-adder1*1000; 
  adder2=gao/100,gao=gao-adder2*100; 
  adder3=gao/10,adder4=gao%10; 
  
  wr_lcd(comm,p); 
      wr_lcd(dat,caidan1[adder1]);delay(20); 
      wr_lcd(dat,caidan1[adder2]);delay(20); 
  wr_lcd(comm,q); 
      wr_lcd(dat,caidan1[adder3]);delay(20); 
      wr_lcd(dat,caidan1[adder4]);delay(20); 


/**************Initialization function****************************************/     
     
void init_port(void) 

  P3DIR=0XBF; //P3.6---A6, 1011 1111 
  P3SEL=0XBF; 
  P3OUT=0X00; 
   
  P4DIR=0XFF; 
  P4SEL=0X00; 
  P4OUT=0; 
   
ADC10CTL0=0; 
  ADC10CTL0 |=REFON+SREF_0; //Positive reference AV CC ,AVSS ground is negative reference 
  ADC10CTL0 |=ADC10ON+ADC10SHT_3+ADC10IE; //Turn on ADC10 core, set sampling and holding time to 64 ADC10CLK, enable ADC10 interrupt 
                 
ADC10CTL1=0; 
   ADC10CTL1|=INCH_6+CONSEQ_0+SHS_0; //Select the 6th channel, the conversion mode is single channel single mode, the sampling signal source is ADC10SC 
   ADC10CTL1|=ADC10SSEL_0+ADC10DIV_3; //Conversion core clock source is ADC10OSC  division coefficient 4 
   delay(20); //Wait for reference to stabilize 
   ADC10CTL0 |=ENC+ADC10SC; //Start AD conversion_EINT 
    
   (); 
    
   return; 



/*******************Main function********************************************/ 
void main(void) 

   WDTCTL=WDTPW+WDTHOLD; //Turn off the watchdog 
    
  BCSCTL1 = CALBC1_1M Hz; //Set DCO to 1MHZ 
  DCOCTL =CALBC1_1MHZ; 
   
  init_port(); 
  init_lcd(); 
   
  chn_disp(xian); 
   
   
  while(1) 
  { 
    ADC10CTL0 &= ~ENC; //Turn off AD conversion 
    ADC10CTL0 |= ENC + ADC10SC; //Start AD conversion  
     
   lcd_mesg(data,0x8b,0x8c); 
    delay(20); 
  } 



#pragma vector = ADC10_VECTOR //ADC10 interrupt service 
__interrupt void adc_isr(void) 

ADC10CTL0 &= ~ENC; //Turn off AD conversion 
      
ad_value=ADC10MEM; //Save AD result ADC10MEM=1023*(Vin/VR+) 

data=((ad_value-390)*10-150); 
ADC10CTL0 |= ENC + ADC10SC; //Start AD conversion  


Reference address:Weighing scale program

Previous article:MSP430 MCU controls stepper motor with display program
Next article:msp430 MCU 18B20 thermometer

Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号