单片机复习题答案(14页).doc
《单片机复习题答案(14页).doc》由会员分享,可在线阅读,更多相关《单片机复习题答案(14页).doc(14页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、-单片机复习题答案-第 14 页复习题考试时间: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();while
2、(1)P1OUT=BIT0;P1OUT=BIT6;_delay_cycles(1000000);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&Push_Key)=0)switch(Push_Key)cas
3、e 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(Freq3)Freq=0;switch(Freq)case 0:BCSCTL1 = CALBC1_1MHZ; DCOCTL =
4、 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驱动程序基础上,编写主程序显示学号。要求画出硬件接线图。主程序:#include#include#include#includema
5、in()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_DisplayDigit(1,2);LCD_DisplayDigit(0,3);LCD_DisplayDigit(3,4);HT1621_Reflash(LCD_Buffer);显示为本人学号试题3:流水灯在提供的TCA6416驱动程序基础上,
6、要求首先实现8个外扩小灯的循环显示即流水灯功能,循环显示方式为:(要求画出硬件接线图)加入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;i8;i+)out0_70 = Out_CMD0;out0_71 = Flag2;F
7、lag2=(Flag21)|0x01;TCA6416_Tx_Frame(out0_7,2);/ 将更新后的数据包,写入芯片寄存器_delay_cycles(16000000);主程序:#include #includevoid main(void)WDTCTL=WDTPW+WDTHOLD;TCA6416A_Init();BCSCTL1 = CALBC1_12MHZ;DCOCTL = CALDCO_12MHZ;while(1)LEDFlash();试题4:按键外部中断要求利用LaunchPad板,P1.3外接按键,控制LED小灯(P1.6)状态,通过外部中断实现。要求画出硬件接线图。主程序:(非
8、常规方法)#includemsp430g2553.hvoid 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;P1D
9、IR&=BIT3;P1IES|=BIT3;P1IE|=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_Oncli
10、ck()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;试题5:定时器利用定时器定时0.5S功能,让小灯亮0.5s,暗0.5s方式闪烁。要求采用定时器中断功能实现。主程序:#includevoid BCSplus_init(void);void main(void)WDTCTL=WDTPW+WDTHO
11、LD;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 = 0x00; BCSCTL1 = CALBC1_1MHZ; /* Set DCO to 1MHz */ DCOCTL = CALDCO_1MHZ; BCSCTL1 |= XT2OFF + DIVA_0;试题6:串口控制小灯亮灭
12、要求通过串口连接实验箱和计算机,编制程序,从PC机发送字符A到单片机,单片机接收后关闭LED小灯。发送字符B到单片机,单片机接收后点亮LED小灯。主程序:#include msp430g2553.hvoid 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
13、 != 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;#pragma vector=USCIAB0RX
14、_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#include#include#includevoid UART_RX(void);unsigned char
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 单片机 复习题 答案 14
限制150内