单片机复习题答案(共18页)_第1页
单片机复习题答案(共18页)_第2页
单片机复习题答案(共18页)_第3页
单片机复习题答案(共18页)_第4页
单片机复习题答案(共18页)_第5页
已阅读5页,还剩13页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、精选优质文档-倾情为你奉上复习题考试时间:90分钟试题1:小灯闪烁要求利用LauncnPad上的LED小灯(P1.0 P1.6),通过循环延时程序控制小灯闪烁,要求修改内部DCO系统时钟,控制小灯闪烁的速度,要求至少有四种明显变化的速度。要求画出硬件接线图。主程序:#include <msp430g2553.h>void GPIO_init();void BCSplus_init(void);void P1_IODect();void P13_Onclick();void main()WDTCTL=WDTPW+WDTHOLD;GPIO_init();_EINT();_enable_

2、interrupts();while(1)P1OUT=BIT0;P1OUT=BIT6;_delay_cycles();void GPIO_init()P1DIR|=BIT0+BIT6;P1OUT|=BIT0;P1OUT&=BIT6;P1IFG&=BIT0;P1REN|=BIT3;P1OUT|=BIT3;P1DIR&=BIT3;P1IES|=BIT3;P1IE|=BIT3;void P1_IODect()unsigned char Push_Key=0;Push_Key=P1IFG&(P1DIR);_delay_cycles(10000);if(P1IN&

3、Push_Key)=0)switch(Push_Key)case BIT0: break;case 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&=0X00;_EINT();void P13_Onclick()static unsigned int Freq=0;if(Freq>3)Freq=0;switch(Freq

4、)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+;试题2:LCD显示学号在提供的段式LCD驱动程序基础上,编写主程序显示学号。要求画出硬件接线图

5、。主程序:#include<msp430g2553.h>#include<LCD_128.h>#include<TCA6416A.h>#include<HT1621.h>main()WDTCTL=WDTPW+WDTHOLD;TCA6416A_Init();HT1621_init();while(1)LCD_DisplayDigit(1,10);LCD_DisplayDigit(4,9);LCD_DisplayDigit(8,8);LCD_DisplayDigit(4,7);LCD_DisplayDigit(1,1);LCD_DisplayDigi

6、t(1,2);LCD_DisplayDigit(0,3);LCD_DisplayDigit(3,4);HT1621_Reflash(LCD_Buffer);显示为本人学号试题3:流水灯在提供的TCA6416驱动程序基础上,要求首先实现8个外扩小灯的循环显示即流水灯功能,循环显示方式为:(要求画出硬件接线图) àààààààà加入TCA6416A.cvoid LEDFlash(void)unsigned char out0_72=0;unsigned char Flag1=0x7F;unsigned char Fla

7、g2=0xFE;unsigned int i;for(i=0;i<8;i+)out0_70 = Out_CMD0;out0_71 = Flag1;Flag1=(Flag1>>1)|0x80;TCA6416_Tx_Frame(out0_7,2);/ 将更新后的数据包,写入芯片寄存器_delay_cycles(); for(i=0;i<8;i+) out0_70 = Out_CMD0;out0_71 = Flag2;Flag2=(Flag2<<1)|0x01;TCA6416_Tx_Frame(out0_7,2);/ 将更新后的数据包,写入芯片寄存器_delay_

8、cycles(); 主程序:#include <msp430g2553.h>#include<TCA6416A.h>void main(void)WDTCTL=WDTPW+WDTHOLD;TCA6416A_Init();BCSCTL1 = CALBC1_12MHZ;DCOCTL = CALDCO_12MHZ;while(1)LEDFlash();试题4:按键外部中断要求利用LaunchPad板,P1.3外接按键,控制LED小灯(P1.6)状态,通过外部中断实现。要求画出硬件接线图。主程序:(非常规方法)#include"msp430g2553.h"v

9、oid P13_Onclick();void P1_IODect();void GPIO_init();void main(void)WDTCTL=WDTPW+WDTHOLD;GPIO_init();_EINT();TACTL=TASSEL_2+ID_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&=BIT3;P1IES|=BIT3;P1

10、IE|=BIT3;#pragma vector =PORT1_VECTOR_interrupt void PORT1_ISR(void)P1_IODect();P1IFG=0;void P1_IODect()unsigned int key=0;key=P1IFG&(P1DIR);_delay_cycles(10000);if(P1IN&key)=0)switch(key)/case BIT0:P10_Onclick();break;case BIT3:P13_Onclick();break;default:break;void P13_Onclick()static unsi

11、gned 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;试题5:定时器利用定时器定时0.5S功能,让小灯亮0.5s,暗0.5s方式闪烁。要求采用定时器中断功能实现。主程序:#include<msp430g2553.h>void BCSplus_init(void);void main(void)WDTCTL=W

12、DTPW+WDTHOLD;BCSplus_init();P1SEL=0X00;P1DIR|=0X01;P1OUT|=0X01;while(1)P1OUT=0X01;_delay_cycles();void BCSplus_init(void) BCSCTL2 = SELM_0 + DIVM_0 + DIVS_0; if (CALBC1_1MHZ != 0xFF) DCOCTL = 0x00; BCSCTL1 = CALBC1_1MHZ; /* Set DCO to 1MHz */ DCOCTL = CALDCO_1MHZ; BCSCTL1 |= XT2OFF + DIVA_0;试题6:串口控制

13、小灯亮灭要求通过串口连接实验箱和计算机,编制程序,从PC机发送字符A到单片机,单片机接收后关闭LED小灯。发送字符B到单片机,单片机接收后点亮LED小灯。主程序:#include "msp430g2553.h"void 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

14、;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 + UCBRS_1; UCA0BR0 = 104; UCA0CTL1 &= UCSWRST; IFG2 &= (UCA0RXIFG); IE2 |= UCA0RXIE; _bis_SR_register(GIE); LPM0;

15、#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')P1OUT&=BIT0;while (!(IFG2&UCA0TXIFG);UCA0TXBUF=temp;题7:串口通信要求通过串口连接实验箱和计算机,编制程序,从PC机发送字符到单片机,单片机在LCD上显示接收到的字符。#include<m

16、sp430g2553.h>#include<LCD_128.h>#include<TCA6416A.h>#include<HT1621.h>void 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

17、) DCOCTL = 0x00; BCSCTL1 = CALBC1_1MHZ; /* Set DCO to 1MHz */ DCOCTL = CALDCO_1MHZ; UCA0CTL1 |= UCSWRST; UCA0CTL1 = UCSSEL_2 + UCSWRST; UCA0MCTL = UCBRF_0 + UCBRS_1; UCA0BR0 = 104; UCA0CTL1 &= UCSWRST; IFG2 &= (UCA0RXIFG); IE2 |= UCA0RXIE; _bis_SR_register(GIE); LPM0;#pragma vector=USCIAB0RX

18、_VECTOR_interrupt void USCI0RX_ISR_HOOK(void)UART_RX();void UART_RX(void)temp=UCA0RXBUF;TCA6416A_Init();HT1621_init();LCD_DisplayDigit(temp-48,6);HT1621_Reflash(LCD_Buffer);while (!(IFG2&UCA0TXIFG);UCA0TXBUF=temp;r试题8:定时器使用单片机的内部定时器模块,制作电子钟并通过液晶显示时间信息。电子钟能正常运行时在LCD液晶上显示”XX:XX:XX”(时分秒)主程序:#includ

19、e<msp430g2553.h>#include<LCD_128.h>#include<TCA6416A.h>#include<HT1621.h>int i,j=0,a1,a2,a3;void js();void 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_DisplayS

20、eg(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;LCD_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();HT1

21、621_Reflash(LCD_Buffer);void GPIO_init()P1REN|=BIT3;P1OUT|=BIT3;P1DIR&=BIT3;P1IES|=BIT3;P1IE|=BIT3;试题9:温度测量显示要求MSP430G2553单片机ADC,内部温度传感器进行测量,并把温度结果通过LCD显示。要求画出硬件接线图。主程序:#include <msp430.h>#include <ti/mcu/msp430/csl/CSL.h>#include<msp430g2553.h>#include<LCD_128.h>#include

22、<TCA6416A.h>#include<HT1621.h>void ADC10_init(void);void BCSplus_init(void);long IntDegc;unsigned int Value;int main(int argc, char *argv) /WDTplus_init(); WDTCTL=WDTPW+WDTHOLD; TCA6416A_Init(); HT1621_init(); BCSplus_init(); ADC10_init(); while(1) ADC10CTL0|= ENC+ADC10SC; /while(ADC10DT

23、CL1&BIT0); Value=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(50); LCD_DisplaySeg(63); LCD_DisplaySeg(57)

24、; 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 char c);void putstr(uns

25、igned char *s);void main(void) WDTCTL = WDTPW + WDTHOLD; / Stop WDT if (CALBC1_1MHZ=0xFF) / If calibration constant erased while(1); / do not load, trap CPU! DCOCTL = 0; / Select lowest DCOx and MODx settings BCSCTL1 = CALBC1_1MHZ; / Set DCO DCOCTL = CALDCO_1MHZ; P1DIR|=BIT6; P1DIR |= BIT2; /P1.2 UA

26、RT_TX P1DIR &=BIT1; /P1.2 UART_RX P1SEL |= BIT1+BIT2; /select P1.1 and P1.2 as UART port P1SEL2 |= BIT1+BIT2; UCA0CTL1 |= UCSWRST; UCA0CTL1 = UCSSEL_2 + UCSWRST; UCA0MCTL = UCBRF_0 + UCBRS_1; UCA0BR0 = 104; UCA0CTL1 &= UCSWRST; IE2 |= UCA0RXIE; _EINT(); putstr(string); LPM0; /_bis_SR_registe

27、r(LPM0_bits + GIE); / Enter LPM0, interrupts enabled#pragma vector=USCIAB0RX_VECTOR_interrupt void USCIA0_ISR(void)while (!(IFG2&UCA0TXIFG); / USCI_A0 TX buffer ready?UCA0TXBUF = UCA0RXBUF; temp=UCA0RXBUF; if(temp='A') P1OUT|=BIT6; else P1OUT&=BIT6; void putchar(unsigned char c)while

28、 (!(IFG2&UCA0TXIFG);UCA0TXBUF=c;void putstr(unsigned char *s)IE2&=UCA0RXIE;while(*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亮度。要求至少实现四级亮度变化。#include <msp430g2553.h>void GPIO_init();void BCSplus_init(void);void P1_IODect

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论