1、第 1 页 共 18 页复习题考试时间:90 分钟试题 1:小灯闪烁要求利用 LauncnPad 上的 LED 小灯(P1.0 P1.6),通过循环延时程序控制小灯闪烁,要求修改内部 DCO 系统时钟,控制小灯闪烁的速度,要求至少有四种明显变化的速度。要求画出硬件接线图。主程序:#include void GPIO_init();void BCSplus_init(void);void P1_IODect();void P13_Onclick();void main()WDTCTL=WDTPW+WDTHOLD;GPIO_init();_EINT();_enable_interrupts();w
2、hile(1)P1OUT=BIT0;P1OUT=BIT6;_delay_cycles(1000000);void GPIO_init()P1DIR|=BIT0+BIT6;P1OUT|=BIT0;P1OUTP1IFGP1REN|=BIT3;P1OUT|=BIT3;P1DIRP1IES|=BIT3;第 2 页 共 18 页P1IE|=BIT3;void P1_IODect()unsigned char Push_Key=0;Push_Key=P1IFG_delay_cycles(10000);if(P1INcase BIT1: break;case BIT2: break;case BIT3: P
3、13_Onclick();break;default:break;#pragma vector=PORT1_VECTOR_interrupt void P1_ISR(void)_DINT();P1_IODect();P1IFG_EINT();void P13_Onclick()static unsigned int Freq=0;if(Freq3)Freq=0;switch(Freq)case 0:BCSCTL1 = CALBC1_1MHZ; DCOCTL = CALDCO_1MHZ;break;case 1:BCSCTL1 = CALBC1_8MHZ; DCOCTL = CALDCO_8MH
4、Z;break;第 3 页 共 18 页case 2:BCSCTL1 = CALBC1_12MHZ; DCOCTL = CALDCO_12MHZ;break;case 3:BCSCTL1 = CALBC1_16MHZ; DCOCTL = CALDCO_16MHZ;break;default:break;Freq+;试题 2:LCD 显示学号在提供的段式 LCD 驱动程序基础上,编写主程序显示学号。要求画出硬件接线图。主程序:#include#include#include#includemain()WDTCTL=WDTPW+WDTHOLD;TCA6416A_Init();HT1621_init
5、();while(1)LCD_DisplayDigit(1,10);LCD_DisplayDigit(4,9);LCD_DisplayDigit(8,8);LCD_DisplayDigit(4,7);LCD_DisplayDigit(1,1);LCD_DisplayDigit(1,2);LCD_DisplayDigit(0,3);LCD_DisplayDigit(3,4);HT1621_Reflash(LCD_Buffer);显示为本人学号试题 3:流水灯在提供的 TCA6416 驱动程序基础上,要求首先实现 8 个外扩小灯的循环显示即流水灯第 4 页 共 18 页功能,循环显示方式为:(要求
6、画出硬件接线图 ) 加入 TCA6416A.cvoid LEDFlash(void)unsigned char out0_72=0;unsigned char Flag1=0x7F;unsigned char Flag2=0xFE;unsigned int i;for(i=0;i1)|0x80;TCA6416_Tx_Frame(out0_7,2); / 将更新后的数据包,写入芯片寄存器_delay_cycles(16000000);for(i=0;i#includevoid main(void)第 5 页 共 18 页WDTCTL=WDTPW+WDTHOLD;TCA6416A_Init();B
7、CSCTL1 = CALBC1_12MHZ;DCOCTL = CALDCO_12MHZ;while(1)LEDFlash();试题 4:按键外部中断要求利用 LaunchPad 板,P1.3 外接按键,控制 LED 小灯(P1.6 )状态,通过外部中断实现。要求画出硬件接线图。主程序:(非常规方法)#include“msp430g2553.h“void P13_Onclick();void P1_IODect();void GPIO_init();void main(void)WDTCTL=WDTPW+WDTHOLD;GPIO_init();_EINT();TACTL=TASSEL_2+ID_
8、0+MC_1+TACLR+TAIE+TAIFG;TACCTL1=OUTMOD_7;TACCR0=500;_BIS_SR(LPM0_bits+GIE);LPM3;void GPIO_init()P1DIR|=BIT6;P1SEL|=BIT6;P1REN|=BIT3;P1OUT|=BIT3;P1DIR第 6 页 共 18 页P1IES|=BIT3;P1IE|=BIT3;#pragma vector =PORT1_VECTOR_interrupt void PORT1_ISR(void)P1_IODect();P1IFG=0;void P1_IODect()unsigned int key=0;ke
9、y=P1IFG_delay_cycles(10000);if(P1INbreak;case BIT3:P13_Onclick();break;default:break;void P13_Onclick()static unsigned int Freq=0;if(Freq=3)Freq=0;else Freq+;switch(Freq)case 0:TACCR1=100;break;case 1:TACCR1=0;break;case 2:TACCR1=100;break;case 3:TACCR1=0;break;default:break;第 7 页 共 18 页试题 5:定时器利用定时
10、器定时 0.5S 功能,让小灯亮 0.5s,暗 0.5s 方式闪烁。要求采用定时器中断功能实现。主程序:#includevoid BCSplus_init(void);void main(void)WDTCTL=WDTPW+WDTHOLD;BCSplus_init();P1SEL=0X00;P1DIR|=0X01;P1OUT|=0X01;while(1)P1OUT=0X01;_delay_cycles(500000);void BCSplus_init(void)BCSCTL2 = SELM_0 + DIVM_0 + DIVS_0;if (CALBC1_1MHZ != 0xFF) DCOCTL
11、 = 0x00;BCSCTL1 = CALBC1_1MHZ; /* Set DCO to 1MHz */DCOCTL = CALDCO_1MHZ;第 8 页 共 18 页BCSCTL1 |= XT2OFF + DIVA_0;试题 6:串口控制小灯亮灭要求通过串口连接实验箱和计算机,编制程序,从 PC 机发送字符 A 到单片机,单片机接收后关闭 LED 小灯。发送字符 B 到单片机,单片机接收后点亮 LED 小灯。主程序:#include “msp430g2553.h“void UART_RX(void);unsigned char temp;void main(void)/ CSL_init(
12、); / Activate Grace-generated configurationWDTCTL = WDTPW + WDTHOLD;P1DIR|=BIT0;P1SEL = BIT1 + BIT2;P1SEL2 = BIT1 + BIT2;if (CALBC1_1MHZ != 0xFF) DCOCTL = 0x00;BCSCTL1 = CALBC1_1MHZ; /* Set DCO to 1MHz */DCOCTL = CALDCO_1MHZ;UCA0CTL1 |= UCSWRST;UCA0CTL1 = UCSSEL_2 + UCSWRST;UCA0MCTL = UCBRF_0 + UCBR
13、S_1;UCA0BR0 = 104;UCA0CTL1 IFG2 IE2 |= UCA0RXIE;_bis_SR_register(GIE);LPM0;第 9 页 共 18 页#pragma vector=USCIAB0RX_VECTOR_interrupt void USCI0RX_ISR_HOOK(void)UART_RX();void UART_RX(void)temp=UCA0RXBUF;if(temp=B)P1OUT|=BIT0;Else if(temp=A)P1OUTwhile (!(IFG2UCA0TXBUF=temp;题 7:串口通信要求通过串口连接实验箱和计算机,编制程序,从
14、PC 机发送字符到单片机,单片机在 LCD 上显示接收到的字符。#include#include#include#includevoid UART_RX(void);unsigned char temp;void main(void)/ CSL_init(); / Activate Grace-generated configurationWDTCTL = WDTPW + WDTHOLD;P1DIR|=BIT0;P1SEL = BIT1 + BIT2;P1SEL2 = BIT1 + BIT2;if (CALBC1_1MHZ != 0xFF) DCOCTL = 0x00;第 10 页 共 18
15、页BCSCTL1 = CALBC1_1MHZ; /* Set DCO to 1MHz */DCOCTL = CALDCO_1MHZ;UCA0CTL1 |= UCSWRST;UCA0CTL1 = UCSSEL_2 + UCSWRST;UCA0MCTL = UCBRF_0 + UCBRS_1;UCA0BR0 = 104;UCA0CTL1 IFG2 IE2 |= UCA0RXIE;_bis_SR_register(GIE);LPM0;#pragma vector=USCIAB0RX_VECTOR_interrupt void USCI0RX_ISR_HOOK(void)UART_RX();void
16、UART_RX(void)temp=UCA0RXBUF;TCA6416A_Init();HT1621_init();LCD_DisplayDigit(temp-48,6);HT1621_Reflash(LCD_Buffer);while (!(IFG2UCA0TXBUF=temp;r试题 8:定时器使用单片机的内部定时器模块,制作电子钟并通过液晶显示时间信息。电子钟能正常运行时在 LCD 液晶上显示”XX:XX:XX”( 时分秒)主程序:#include第 11 页 共 18 页#include#include#includeint i,j=0,a1,a2,a3;void js();void
17、GPIO_init();main()WDTCTL=WDTPW+WDTHOLD;TCA6416A_Init();HT1621_init();GPIO_init();js();void js(void)TCA6416A_Init();HT1621_init();_DINT();while(1)i+;if(i%2)LCD_DisplaySeg(99);LCD_DisplaySeg(83);if(i%2=0)LCD_ClearSeg(83);LCD_ClearSeg(99);a1=i/3600;a2=(i-a1*3600)/60;a3=i-a1*3600-a2*60;第 12 页 共 18 页LCD_
18、DisplayDigit(a1/10%6,1);LCD_DisplayDigit(a1%10,2 );LCD_DisplayDigit(a2/10%6,3);LCD_DisplayDigit(a2%10,4);LCD_DisplayDigit(a3/10%6,5);LCD_DisplayDigit(a3%10,6);_delay_cycles(1000000);HT1621_Reflash(LCD_Buffer);void GPIO_init()P1REN|=BIT3;P1OUT|=BIT3;P1DIRP1IES|=BIT3;P1IE|=BIT3;试题 9:温度测量显示要求 MSP430G25
19、53 单片机 ADC,内部温度传感器进行测量,并把温度结果通过 LCD显示。要求画出硬件接线图。主程序:#include #include #include#include#include#includevoid ADC10_init(void);void BCSplus_init(void);long IntDegc;unsigned int Value;int main(int argc, char *argv)第 13 页 共 18 页/WDTplus_init();WDTCTL=WDTPW+WDTHOLD;TCA6416A_Init();HT1621_init();BCSplus_in
20、it();ADC10_init();while(1)ADC10CTL0|= ENC+ADC10SC;/while(ADC10DTCL1Value=ADC10MEM;IntDegc=(Value-673)*423)/1024;LCD_DisplayDigit(IntDegc/100,1);LCD_DisplayDigit(IntDegc/10%10,2);LCD_DisplayDigit(IntDegc%10,3);LCD_DisplaySeg(24);LCD_DisplaySeg(51);LCD_DisplaySeg(55);LCD_DisplaySeg(54);LCD_DisplaySeg(
21、50);LCD_DisplaySeg(63);LCD_DisplaySeg(57);LCD_DisplaySeg(56);LCD_DisplaySeg(59);HT1621_Reflash(LCD_Buffer);/return (0);试题 10:信号周期检测,并通过串口显示。要求利用定时器的输入捕捉功能,检测输入信号周期,并通过串口发送给 PC 显示。#include “msp430g2553.h“unsigned char temp;unsigned char string=“Please input controled number:“;void putchar(unsigned ch
22、ar c);void putstr(unsigned char *s);第 14 页 共 18 页void main(void)WDTCTL = WDTPW + WDTHOLD; / Stop WDTif (CALBC1_1MHZ=0xFF) / If calibration constant erasedwhile(1); / do not load, trap CPU!DCOCTL = 0; / Select lowest DCOx and MODx settingsBCSCTL1 = CALBC1_1MHZ; / Set DCODCOCTL = CALDCO_1MHZ;P1DIR|=BI
23、T6;P1DIR |= BIT2; /P1.2 UART_TXP1DIR /P1.2 UART_RXP1SEL |= BIT1+BIT2; /select P1.1 and P1.2 as UART portP1SEL2 |= BIT1+BIT2;UCA0CTL1 |= UCSWRST;UCA0CTL1 = UCSSEL_2 + UCSWRST;UCA0MCTL = UCBRF_0 + UCBRS_1;UCA0BR0 = 104;UCA0CTL1 IE2 |= UCA0RXIE;_EINT();putstr(string);LPM0;/_bis_SR_register(LPM0_bits +
24、GIE); / Enter LPM0, interrupts enabled#pragma vector=USCIAB0RX_VECTOR_interrupt void USCIA0_ISR(void)第 15 页 共 18 页while (!(IFG2 / USCI_A0 TX buffer ready?UCA0TXBUF = UCA0RXBUF;temp=UCA0RXBUF;if(temp=A)P1OUT|=BIT6;elseP1OUTvoid putchar(unsigned char c)while (!(IFG2UCA0TXBUF=c;void putstr(unsigned cha
25、r *s)IE2while(*s)!=0)putchar(*s);s+;putchar(n);IE2|=UCA0RXIE;TACTL=TASSEL_2+MC_2+TAIE+TACLR; TACTL=TASSEL_2+MC_2+TAIE+TACLR;试题 11:PWM 控制小灯亮度要求利用 LaunchPad 开发板上 P1.3 按键,P1.6TA 输出口接 LED(用跳线帽连接) ,编写一段代码,通过按键改变 PWM 占空比,从而改变 LED 亮度。要求至少实现四级亮第 16 页 共 18 页度变化。#include void GPIO_init();void BCSplus_init(voi
26、d);void P1_IODect();void P13_Onclick();void main()WDTCTL=WDTPW+WDTHOLD;GPIO_init();_EINT();_enable_interrupts();while(1)P1OUT=BIT0;P1OUT=BIT6;_delay_cycles(1000000);void GPIO_init()P1DIR|=BIT0+BIT6;P1OUT|=BIT0;P1OUTP1IFGP1REN|=BIT3;P1OUT|=BIT3;P1DIRP1IES|=BIT3;P1IE|=BIT3;void P1_IODect()unsigned cha
27、r Push_Key=0;Push_Key=P1IFG第 17 页 共 18 页_delay_cycles(10000);if(P1INcase BIT1: break;case BIT2: break;case BIT3: P13_Onclick();break;default:break;#pragma vector=PORT1_VECTOR_interrupt void P1_ISR(void)_DINT();P1_IODect();P1IFG_EINT();void P13_Onclick()static unsigned int Freq=0;if(Freq3)Freq=0;switch(Freq)case 0:BCSCTL1 = CALBC1_1MHZ; DCOCTL = CALDCO_1MHZ;break;case 1:BCSCTL1 = CALBC1_8MHZ; DCOCTL = CALDCO_8MHZ;break;case 2:BCSCTL1 = CALBC1_12MHZ; DCOCTL = CALDCO_12MHZ;break;case 3:BCSCTL1 = CALBC1_16MHZ; DCOCTL = CALDCO_16MHZ;break;default:break;Freq+;第 18 页 共 18 页