|
EDA365欢迎您!
您需要 登录 才可以下载或查看,没有帐号?注册
x
本程序是单片机MSP430G2553
" {) v; D8 I ^1 j0 y0 u P1.2----------------------------UCA0TXD 串口发送端9 \5 t" W( L; x- f; j
P1.1----------------------------UCA0RXD 串口接受端6 L% D7 Q: z$ u2 R, v6 V2 |) w
P1.0----------------------------红灯指示
7 o X5 z+ w* K9 F- U( s D5 a P1.6----------------------------绿灯指示1 M, A# l; R; Q$ o
P1.5----------------------------模拟电压输入" w* r& r2 p7 S; S- I, e' n9 \& ~4 w
利用主辅时钟为1MHZ,串口波特率9600,& g7 p3 e! k9 o+ j& Z
波特率:1000000/9600=104# b; [% h! ^" c* |
UCA0BR0 = 104; // 1MHz 9600
1 P# P1 e% u' R$ A7 J UCA0BR1 = 0; // 1MHz 9600
! G. ~- Q1 D# a1 ]3 Z [; k
4 j) V8 Z) U: m. d现象:
+ U( J5 j% C; |' q' T; n: g- z& A1 _ 功能(1)看到 P1.5口输入不同的电压经AD采样后发送
/ q/ S& N2 j; b7 O( o& M# I 功能(2)打开电脑串口调试助手,发送区有数据待发送时,在接受区将看到相应的数据。4 x5 u* j- J- t/ Y8 b0 d
******************************************************************************/
' `# {# t1 F# L+ s" h#include <msp430g2553.h>4 b* i' J/ c6 U, y
float adc_voltage;3 D/ n$ D! I6 a5 b
unsigned int k;/ G: k2 R1 {4 G' o. M9 I, S
void sys_clk_config(void)
; `2 Q2 P: R6 @/ R( T9 v( W7 Q{
: C$ G& d# \. ]: J) j8 l$ s' Z //ACLK = ; MCLK = SMCLK = DCOCLK = 1.1MHZ
2 @0 _% V& P( r- O9 J' p DCOCTL = 0;
8 |, ?: ~. n6 S+ a6 ^& ~ BCSCTL1 = CALBC1_1MHZ;
2 y2 r0 N* H) l! O* W5 l) I& R A9 q DCOCTL = CALDCO_1MHZ;
8 b+ @5 N6 o+ K9 I/ l3 ]}
4 M d8 H9 |6 a3 I- f- E: c, hvoid uart_gpio_init(void)
: G5 B8 C1 `& ^& o; Y{% w7 a/ f! Q/ ~' o/ M. s; ]; o" W
//P1SEL |= BIT1 + BIT2;
# ?/ a9 `; W# A5 A" b# Z9 F //P1SEL2 |= BIT1 + BIT2;
* B% h: j- q) p, H //P1DIR |= BIT2;
9 x6 _5 U, V, I, y P1DIR = 0xFF; // All P1.x outputs
, w2 h c, N* l( ? P1OUT = 0; // All P1.x reset
' b# F3 J# `6 \$ e3 I7 z, ]0 Z) L- s5 w P1SEL |= BIT1 + BIT2 + BIT4; // P1.1 = RXD, P1.2=TXD: D1 x+ @% m$ I6 f
P1SEL2 |= BIT1 + BIT2; // P1.4 = SMCLK, others GPIO
% w1 s3 ?0 h. R. f) b5 N P2DIR = 0xFF; // All P2.x outputs! U+ L! o) b0 n; @' m8 w
}# h8 M% K8 u1 T" }3 D) H
void led_gpio_init(void)
2 D8 V& h% c$ z7 Q0 g) g{
" ?+ `3 L: O0 w) L3 c}
7 ]1 S1 E+ I/ b( g( E/ L! bvoid ad_gpio_init(void)) P( r$ v1 e% L$ r3 |+ S) u
{
& n+ M9 L* k) H# l J! x6 M}
- l1 h. c! [' B' R* O# cvoid uart_config(void)3 h$ S+ o0 g1 w: ^, W& X! \
{
; _6 d3 T% {8 V4 s) r7 VUCA0CTL1 |= UCSSEL_2;9 G' b) y/ c% ^- A5 t5 g! M, {
& i T+ a# a) {( n# q0 ?
UCA0BR0 = 104; // 1MHz 9600
+ G# N# t1 y9 D5 s UCA0BR1 = 0; // 1MHz 9600& m! s2 c l# m/ E; G5 ^
UCA0MCTL = UCBRS2 + UCBRS0;
3 h. T" Z* I& Y- k7 n. v* W UCA0CTL1 &= ~UCSWRST;
3 Q- ]+ \; C: W IE2 |= UCA0RXIE;
# g, [# x6 `. b+ _- n) z! ] , y6 z2 h0 N( d* E/ v) A% K
}
: R# x! x6 {! R! E/ ]0 I pvoid ad_config(void) o3 W5 h F: a8 z6 O
{! `$ H7 l) f# A" ]% A
ADC10CTL0 = ADC10SHT_2 + MSC + ADC10ON + ADC10IE;; Y% z$ v- p3 d2 O+ j( F. k9 b
* ~% h7 V/ _) j8 N
ADC10CTL1 = INCH_5 + CONSEQ_2 ;
1 K# d$ ^/ L7 i7 A' p a ADC10AE0 |= 0x10;
! F; I! o6 H8 i4 T4 L2 ~& n8 ~/ O" m! a( N2 t# L2 o
ADC10CTL0 |= ENC + ADC10SC;* T; h+ T( T' p- H
4 J4 x8 d: D# y% \}4 K- _. c" G# }9 }8 m: K
void main()5 h. q, q! }0 e$ p' B
{
( y% \, X# Y. d6 \7 c WDTCTL = WDTPW + WDTHOLD;8 B0 X% C& s8 Z( a0 o- r$ a
, w/ D) a# s( L. z& C0 J, { //sys_clk_config();& B, f* `0 V F0 I$ H
/ g5 Y7 m7 s9 v
uart_gpio_init();; `6 i' |$ A% x# A& D3 s6 J% h, M! T
. T+ J7 k7 t+ K9 a E# _' K led_gpio_init();
% N# a, N& t/ v$ g3 q
( L2 F, z% z# t! J! d ad_gpio_init();9 R+ F, S% o" B5 B
. G1 @: t' k; {2 q8 c* e, d& E
uart_config();
# q; l% T" w2 j: r0 x) { b; i! e
ad_config();
6 ]9 V/ |1 o% }. I! a( \5 U __bis_SR_register(GIE);
8 H, n7 A7 Q7 h% O3 B6 T3 |8 p0 e while(1);; M/ \3 `/ J5 E& d
9 Z& s6 N8 z ?9 i
$ \; e3 W( Q- p
}1 C6 y9 y( {8 y% |9 W: ^
#pragma vector = USCIAB0RX_VECTOR
- i2 d4 S; L- y; Z, S: O9 [; G__interrupt void USCI0RX_ISR(void)
0 Y( e C9 k, } D6 |{. @. O9 G% D' d
while(!(IFG2 & UCA0TXIFG));6 }4 T6 T+ o; ]7 J* f c0 S
// UCA0TXBUF =0x33 ;// UCA0RXBUF;1 H4 i: S( U+ L4 ]9 q
}1 G2 f! \9 F' y6 T0 c y# S
#pragma vector = ADC10_VECTOR
, {; a, n7 s$ x+ m9 z. P; [# @# T/ V__interrupt void ADC10_A0_ISR(void)$ u' s% U% `2 h3 T8 h
{
' B; m. @( h: E: u ~4 U4 d2 g2 u3 E7 }" n/ t+ z- F) S9 G
while(!(IFG2 & UCA0TXIFG));+ q+ D' O. u8 G( R
UCA0TXBUF = ((ADC10MEM*33)/1023);
* o& T( t1 x# `3 c( O6 e' a$ j, v' H' {/ I k = 10000;
9 F m6 e9 k# Y: n+ M% ]# C4 \ while(k--);3 a; P+ R2 Z! A- H U
; v0 P1 ^; n J& F/ n/ n2 l
} |
|