MSP430 MCU Timer B Interrupt Experiment

Publisher:等放假的LwjLatest update time:2015-05-14 Source: 51heiKeywords:MSP430 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
This program is based on the internal timer B interrupt experiment of MSP430 single chip. Function: Use timer B to accurately set the time interval of the running light.
#include "MSP430F149.h"
#define uchar unsigned char
#define uint unsigned int 
uchar LedData=0x80;
uchar num=50;//Interrupt 50 times to shift the LED right by one position
//Timer A initialization
void InitTimerB(){
  TBCTL=TBSSEL1+ID1+ID0+MC0+TBCLR;//Select 1/8SMCLK to clear TAR
  TBCCTL0=CCIE;//CCR0 interrupt enables comparison mode
  TBCCR0=10000;//Time interval 10ms
}
//Timer A interrupt
#pragma  vector =TIMERB0_VECTOR
__interrupt void TimerBINT(){
  num--;
  if(num==0){
    LedData>>=1;//Shift right one bit
    if(LedData==0x00) LedData=0x80;
    P4OUT=LedData;//P4 port output data
    num=50;//50 interrupts is 0.5s
  }
}
void main(){
  InitClock();//Initialize clock
  InitTimerB();//Timer B initialization
  P4DIR=0xFF;//P4 port output direction
  _EINT();//Open interrupt
  while(1);
}
Keywords:MSP430 Reference address:MSP430 MCU Timer B Interrupt Experiment

Previous article:Robotics Tutorial 4: Infrared Tracking and LM339 Module
Next article:Detailed explanation and program of single chip microcomputer external interrupt

Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号