#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
}
Previous article:MSP430 MCU controls stepper motor with display program
Next article:msp430 MCU 18B20 thermometer
- Popular Resources
- Popular amplifiers
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- Keysight Technologies Helps Samsung Electronics Successfully Validate FiRa® 2.0 Safe Distance Measurement Test Case
- Innovation is not limited to Meizhi, Welling will appear at the 2024 China Home Appliance Technology Conference
- Innovation is not limited to Meizhi, Welling will appear at the 2024 China Home Appliance Technology Conference
- Huawei's Strategic Department Director Gai Gang: The cumulative installed base of open source Euler operating system exceeds 10 million sets
- Download from the Internet--ARM Getting Started Notes
- Learn ARM development(22)
- Learn ARM development(21)
- Learn ARM development(20)
- Learn ARM development(19)
- Learn ARM development(14)
- EEWORLD University - Analysis and Design of Analog Integrated Circuits
- Has anyone tried the GD32E230 board?
- [Liquid Level Sensor Evaluation] Capacitive-non-contact sensor response to container media
- Recruiting antenna RF part-time teacher
- Very detailed introductory article FPGA_SOPC_starter.pdf
- 13S, 48V lithium-ion battery pack for electric bicycles and electric motorcycles
- The era of UWB is coming, are you ready?
- [Perf-V Evaluation] Development of Hummingbird Timer Interrupt Based on Perf-V Development Board
- 485 Communication abnormality
- What is the difference between hot ground and cold ground in a power supply?