|
EDA365欢迎您!
您需要 登录 才可以下载或查看,没有帐号?注册
x
本程序是单片机MSP430G2553 4 |- ~* z/ [% [
P1.2----------------------------UCA0TXD 串口发送端
1 F1 ?& r$ o, h9 [: Z$ N P1.1----------------------------UCA0RXD 串口接受端
, c2 Q3 g- C* ]1 H8 t( o P1.0----------------------------红灯指示5 D, N% Z& w1 _% ]/ u- v8 N# e
P1.6----------------------------绿灯指示2 d6 W- B: |; i- E9 S3 y+ v' b
P1.5----------------------------模拟电压输入* e- M" {5 {: d
利用主辅时钟为1MHZ,串口波特率9600,7 l% h+ x& g* J5 {
波特率:1000000/9600=104
- u0 V. y- {( p3 I- q UCA0BR0 = 104; // 1MHz 9600/ ^: X6 `- B" A9 v- ^. d
UCA0BR1 = 0; // 1MHz 9600/ }3 W2 I% H: z" p3 C! M2 \8 Z% E9 {
3 Z1 w2 a# ^ r7 b3 D9 j现象:
8 I; ?( K/ Z/ e$ l3 `+ \6 u9 @# i 功能(1)看到 P1.5口输入不同的电压经AD采样后发送 h. O$ N- X; S8 I) x
功能(2)打开电脑串口调试助手,发送区有数据待发送时,在接受区将看到相应的数据。
. H+ S g" G1 a: h" a! ^$ ]5 s******************************************************************************/
' y2 S. \3 F/ s6 v- v+ f" S#include <msp430g2553.h>- t/ J& b5 z* V9 w+ a' W
float adc_voltage;' w' J$ D) {7 Q" e$ p6 R4 f
unsigned int k;5 w% ]+ ~$ T# r) x) a
void sys_clk_config(void)2 \+ ? w) ?( C9 d; {
{( E+ P9 v0 j' ]
//ACLK = ; MCLK = SMCLK = DCOCLK = 1.1MHZ" j/ T) S2 f0 F0 }
DCOCTL = 0;
& N2 x1 D, t2 u9 S% Z) N6 w/ J BCSCTL1 = CALBC1_1MHZ;1 |& p7 G5 W4 D
DCOCTL = CALDCO_1MHZ;
9 W; m7 a! C' e! D}6 s! T0 ?, b1 I) G. S' ^+ g9 E
void uart_gpio_init(void)
" h, P. @3 z2 }# |; G{( J; p" k& {. k4 K: W* s
//P1SEL |= BIT1 + BIT2;
, S' O; j: f' l/ J+ i( ~( Z //P1SEL2 |= BIT1 + BIT2;
4 e; N. R) `( _1 ?9 N //P1DIR |= BIT2;
9 N1 t# v3 z/ H P1DIR = 0xFF; // All P1.x outputs
* N8 Y4 p+ E' Q5 E! B9 Q L6 i! N P1OUT = 0; // All P1.x reset2 n- W- k9 E- n+ E
P1SEL |= BIT1 + BIT2 + BIT4; // P1.1 = RXD, P1.2=TXD1 c3 ?, h) }7 H( D; V2 q
P1SEL2 |= BIT1 + BIT2; // P1.4 = SMCLK, others GPIO
2 G6 ]* \ |, }% g( h- w% ]! _% e P2DIR = 0xFF; // All P2.x outputs
* h; v% Z' g% N0 R}
3 a1 ? o7 e. e1 W" e, D( Mvoid led_gpio_init(void)
+ P+ M$ V. S/ ?{3 N- h- o8 U* M
}9 R% ^$ C( X2 F3 W; e
void ad_gpio_init(void)3 d0 S& @0 U; ^' E$ |* |
{
* S% X: g1 x- u- ]% B9 ~, u}! x: i$ q4 ]- _1 h; k/ h* H* g5 O% Q% v" v
void uart_config(void)5 G { |# h2 _; C/ j9 @. Q- G
{
$ a; [5 A/ Q! s C) \* jUCA0CTL1 |= UCSSEL_2;
+ L5 H" ~! V8 O* K1 [ - |0 a: G: t: {( E/ r" m
UCA0BR0 = 104; // 1MHz 9600
$ i' K7 t9 d6 P8 K UCA0BR1 = 0; // 1MHz 9600; X% k/ [' D% ]6 ~+ U5 Y' ]
UCA0MCTL = UCBRS2 + UCBRS0;: [0 r ^; B3 D2 R9 r
UCA0CTL1 &= ~UCSWRST;
. ?0 e. L, J4 X6 K. F IE2 |= UCA0RXIE;
5 \- K" Z+ ?9 b, _$ [
/ u& H% [, L, o' F' y- e4 @}% \$ O8 g4 x1 V/ }
void ad_config(void)
- G! x. S+ B: {$ d0 `5 k{% W: B* {( X6 _6 S( W0 @
ADC10CTL0 = ADC10SHT_2 + MSC + ADC10ON + ADC10IE;
" O) A3 m! _2 H" U- E! @
- T+ X2 u% i6 s3 h7 J8 L/ l6 p ADC10CTL1 = INCH_5 + CONSEQ_2 ;
3 b- i K/ D0 m$ K) Q ADC10AE0 |= 0x10;( q7 L3 I# P5 z4 | v, M! B
* Y; |- H5 ?, E6 j8 B ADC10CTL0 |= ENC + ADC10SC;+ r1 w- O5 p4 D) p4 ~' i8 l+ O- L
2 e' W! c6 _) K8 V+ }
}
. K6 \7 q# n% W' Y1 bvoid main()
& N( a v" R5 J) i# O{" I0 H ^6 X9 W0 m! e8 e; @
WDTCTL = WDTPW + WDTHOLD;9 O0 d/ B+ h- A0 e5 }" Z4 D
' g/ Y3 q2 F$ o5 X) G8 y7 T! C" f
//sys_clk_config();0 U+ v% X! A6 M9 o% z
6 `6 c: D5 \! `/ e2 j& E0 o
uart_gpio_init();
, v+ x+ w" Z2 h2 u# I s; E
! [+ `! e G8 s- e8 l led_gpio_init();" P3 i( I( r' b' g
8 w: B. H* q* S9 [3 @6 M
ad_gpio_init();' k/ `9 G+ ]7 Z/ u5 ?8 t* i; e
) G0 I6 s5 V' r" ?( _- u; ?
uart_config();( A% @# R O- `8 Y
/ j/ W9 h7 q0 ^7 h" M# Y+ k" u) o
ad_config();
5 J% f1 S/ k1 z7 _1 k& r# }; x __bis_SR_register(GIE);
$ z i: j& ]8 F: n/ m. T. Z while(1);9 T" X) ]. c8 Q2 t0 I; s
* z( T( ^/ c2 @- S5 W# [
+ w$ P! x4 h% m8 B/ W}
' o4 s0 g; F- V5 E# f6 |#pragma vector = USCIAB0RX_VECTOR( ^* ~' q+ o8 \3 }& D8 n$ X: Y% T1 v
__interrupt void USCI0RX_ISR(void)
7 h* j/ r: v! q$ o9 Z5 x* L7 J{
X' E% J: M% S* s# O3 p while(!(IFG2 & UCA0TXIFG));2 _5 `9 Y' ^+ _* `* n; b3 u
// UCA0TXBUF =0x33 ;// UCA0RXBUF;
( e4 A' E4 f1 f2 q}, |$ U' T6 k% \& A; O
#pragma vector = ADC10_VECTOR, @2 n* C# o' A
__interrupt void ADC10_A0_ISR(void)5 i, @1 I2 B w' X" t2 f% A
{0 ~3 ~. ]5 n- b1 c$ h
9 R( G! t6 K) k: j
while(!(IFG2 & UCA0TXIFG));$ i) Z* `$ ?) s! z9 {
UCA0TXBUF = ((ADC10MEM*33)/1023);! h% @( }3 O3 b' q# e- ~
k = 10000;% ~% X: b$ r1 P' O
while(k--);
+ ]/ \) h, r0 Z8 B& O( T$ v# t; ^+ D: M. j7 k7 M
} |
|