Professional Documents
Culture Documents
Nu in p c vo ln hn v+ th kt qu s l
0x3ff v nu b hn v- th kt qu s l 0.
Configuration :
B iu khin ADC c ci t bi 2 thanh ghi l
ADC10CTL0 v ADC10CTL1 ch c th c
chnh sa khi bit ENC=0 v sau khi chnh sa
xong th bn cn set bit ENC=1 ADC lm vic.
NU BN CHN IN P QUI CHIU NI
Chn ngun in p so snh bng cch set bit REFON ( REFON mt 30
micro giy chuyn trng thi ) . Khi REFON =0 th tc l bn chn
ngun ni AVCC =3.5V, khi REFON =1 th:
*Khi REF2_5V = 1 ,in p qui chiu ni l 2.5 V, = 0,
mode 00, khi n ly mu xong th ngng ADC li bng cch t clear ci bit cho php chy ADC (qun bit no ri). Bn mun c ADC tip th set bit ln
Khi ly mu nhiu ln( c mode 10 v 11) th d liu c lu dng block. Tui cha dng chc nng block ny nhng nh l c c qua. Bn c th c tip phn sau
trong file User's Guide c thm thng tin v my ci Block
MSP430 c DTC (data transfer controller) c chc nng lu mt block data (data t ADC) vo RAM. Trong c thanh ghi ADC10DTC1 xc nh s kt qu chuyn i
s c lu trong RAM t a ch c nh trc trong thanh ghi ADC10SA. Sau khi chuyn i s ln trn knh c chn th s dng c ngt ADC10IFG, lc ny
trong RAM c d liu v bn c th c c
+LPM4: Ci ny th kinh khng hn na. All c s tt ht lun, Ch c duy nht ngt ngoi vi, tc ngt IO c th l ngt t cc port mi nh thc uc
MCU. Mode ny thung dng trong nhng chung trnh ch lm nhim v c d liu t IO nu c thay i, ri x l xong ng tip.
Kt hp vi PWM, thay i sng ca led bng ADC (c t bin tr, cm bin nhit ni)
#include <msp430g2553.h>
#define LED
#define INPUT
void main(void)
{
BIT2
BIT0
// Stop WDT
// P1.2 output
// P1.2 TA0.1 function
BCSCTL1 = CALBC1_1MHZ;
DCOCTL = CALDCO_1MHZ;
TA0CCR0 = 0xffff;
TA0CCTL1 |= OUTMOD_7;
TA0CCR1 = 0;
TACTL = TASSEL_2 + MC_1;
// PWM Period
// CCR1 reset/set
// CCR1 PWM duty cycle
// SMCLK, up mode
Cho e hi vn c, e ang xi con 28 chn v mun dng PORT3 ca n xut ra LCD th mnh defind file LCD.C nh th no,
e sa P2 thnh P3 trong LCD.C ri, sa trong thanh ghi PSEL trong chng trnh chnh na, nhng n chng ra ci g c. V
cho e hi ngha cc dng ny n c lin quan g ti vic xut ra LCD bng PORT 3 ko?
union reg* P2_dir = (union reg*)0x2a;
union reg* P2_out = (union reg*)0x29;
union reg* P1_dir = (union reg*)0x22;
union reg* P1_out = (union reg*)0x21;
/******************************************************************************
*
* www.payitforward.edu.vn
*
******************************************************************************/
/******************************************************************************
*
* C7 TRAINING
*
******************************************************************************/
/******************************************************************************
*
* Module
: TEMPERATURE SENSOR
* Description : This file describes API functions that support for
*
temperature sensor on MSP430G2553
*
* Tool
: CCS 5.1
* Chip
: MSP430G2553
* History
: 04-11-2012
* Version
:1
*
* Author
:
* Notes
: To apply these functions, you must include the header file lcd.h and
*
source file lcd.c to your project.
*
*
******************************************************************************/
/****************************************************************************
* IMPORT
******************************************************************************/
#include <msp430g2553.h>
#include "LCD.h"
/****************************************************************************
* DECLARATIONS
******************************************************************************/
unsigned char temp;
/*****************************************************************************
*
SUBROUTINES
******************************************************************************/
//*****************************************************************************
// Initialization for ADC10 module
//*****************************************************************************
void ADC10_Init(void)
{
ADC10CTL0 = SREF_1 + ADC10SHT_3 + ADC10ON + ADC10IE + REFON;
/*
* Vr+ = Vref+
* ADC sample and hold time = 64 ADC clocks: When using the temperature
sensor, the sample period must be greater than 30 s
* Turn on ADC10
* Enable ADC10 Interrupt
* Turn on reference generator
*/
ADC10CTL1 = INCH_10 + ADC10DIV_1 + ADC10SSEL_3 ;
/*
* Select Input chanel: Temperature Sensor
* ADC10DF = 0: The 10-bit conversion results are right justified
* ADC10 Clock divider: 4
* ADC10 clock source select: SMCLK
*/
}
/*****************************************************************************
*
MAIN PROGRAM
******************************************************************************/
void main(void)
{
WDTCTL = WDTPW + WDTHOLD; //Stop Watchdog Timer
ADC10_Init();
//Initialize ADC10
lcd_init();
//Initialize LCD
P2SEL = 0;
//Turn off external crystal
P2SEL2 = 0;
lcd_clear();
//Clear LCD
while (1)
{
ADC10CTL0 |= ENC + ADC10SC;
//Enable ADC10, Start sample - conversion
_bis_SR_register(LPM0_bits + GIE); //Enter LPM0, wait for sample-conversion finish
lcd_clear();
lcd_gotoxy(2,0);
lcd_puts("Temperature:");
lcd_gotoxy(7,1);
lcd_putc((temp / 10) + 48);
lcd_putc((temp % 10) + 48);
_delay_cycles(500000);
}
/*****************************************************************************
*
INTERRUPT PROGRAM
******************************************************************************/
#pragma vector = ADC10_VECTOR
__interrupt void ADC10_Interrupt(void)
{
temp=((ADC10MEM - 673) * 423) / 1024; //Calculate temperature
/*
* VTEMP=0.00355(TEMPC)+0.986
* Vref = 1.5V
*/
_bic_SR_register_on_exit(LPM0_bits); //Exit LPM0
}
/*****************************************************************************
*
END
******************************************************************************/
c bin tr
c bin tr
/******************************************************************************
*
* WWW.PAYITFORWARD.EDU.VN
*
******************************************************************************/
/******************************************************************************
*
* C7 TRAINING
*
******************************************************************************/
/******************************************************************************
*
* Module
: VOLTAGE MESURE
* Description : This file describes API functions that support for
*
ADC module on MSP430G2553
*
* Tool
: CCS 5.1
* Chip
: MSP430G2553
* History
: 04-11-2012
* Version
:1
*
* Author
: NHH
* Notes
: To apply these functions, you must include the header file lcd.h and
*
source file lcd.c to your project.
*
*
******************************************************************************/
/*****************************************************************************
* Pin Description
******************************************************************************
*
*
MSP430G2x53
*
----------------*
/|\|
XIN|*
||
|
*
--|RST
XOUT|*
|
|
* Analog signal input >--|P1.1/A1
|--> ||
*
|
|--> || Out to LCD
*
|
|--> || Described in LCD.c
*
|
|--> ||
*
|
|
*
******************************************************************************/
/*****************************************************************************
* IMPORT
******************************************************************************/
#include <msp430g2553.h>
#include "LCD.h"
/*****************************************************************************
* DECLARATIONS
******************************************************************************/
#define Vref 3.3
/*****************************************************************************
*
MAIN PROGRAM
******************************************************************************/
void main(void)
{
WDTCTL = WDTPW + WDTHOLD; //Stop Watchdog Timer
ADC10_Init();
//Initialize ADC10
lcd_init();
//Initialize LCD
P2SEL = 0;
//Turn off external crystal
P2SEL2 = 0;
lcd_clear();
//Clear LCD
while (1)
{
ADC10CTL0 |= ENC + ADC10SC; //Enable ADC10, Start sample - conversion
_bis_SR_register(LPM0_bits + GIE); //Enter LPM0, wait for sample-conversion finish
lcd_clear();
lcd_puts("Result: ");
volt = (adc_result * Vref * 100) / 1024; //Calculate result (= 100 * Voltage)
//Display result
lcd_putc((volt / 100) + 48);
//ASCII code (of a number) = number + 48
lcd_puts(".");
lcd_putc((volt / 10) % 10 + 48);
lcd_putc((volt % 10) + 48);
lcd_puts("V");
_delay_cycles(500000);
}
}
/*****************************************************************************
*
INTERRUPT PROGRAM
******************************************************************************/
#pragma vector = ADC10_VECTOR
__interrupt void ADC10_Interrupt(void)
{
adc_result = ADC10MEM;
//Save Result
_bic_SR_register_on_exit(LPM0_bits); //Exit LPM0
}
/*****************************************************************************
*
END OF MAIN.C
******************************************************************************/