我是微控制器领域的新手,我的一个新项目需要你快速帮助。
我正在使用 MSP430F5131。我将解释一下这个项目:我的主要目标是使用 12.8MHz 外部振荡器每秒产生 1 个脉冲。我已经为该项目准备了印刷 PCB,这意味着我必须了解以前的设计师所做的工作并将其实施到我的 CCS 程序中,以便对我的微控制器进行编程。我对整个微控制器世界还是陌生的,我渴望了解更多,尽管我的时间很短。
我附上了 PCB 的电线,以帮助您更多地了解该项目。
对电气接线的一点解释:外部拨动开关(来自连接器 J6“内部/外部选择”)在外部 1pps(来自外部 GPS)或内部 1pps(由 msp430)之间切换。如果我们选择内部模式,则(输入 P2.2)一个“1”(或“0”,如果它是一个低电平有效模式,它是一个低电平有效模式)从 PJ.3(输出)发送到 U4,每个脉冲 1 个第二个从 P2.4 输出到连接器 J8 和 J9(相同的脉冲不同的连接器)。
我可以使用外部拨动开关(J3 连接器的引脚 1,2)或分离器(J3 连接器的引脚 3)将信号切换为 ON/BAD/OFF。如果我将开关切换到开启模式,它会通过 P1.6 向 U5(和门)发送“1”(如果它是低电平有效模式,则发送“0”)并启用脉冲它也发送“1” ' 通过 PJ.0 到 U6 并将脉冲从 TTL 转换为 RS422(差分)。离散切换选项切换脉冲(ON/OFF)的方式与外部拨动开关相同。这是指 PULSE 1 ,我需要为 PULSE 2 实现相同的东西。
虽然我仍然不确定 RST/NMI/SBWTDIO 和 TEST/SBWTCK 是用来连接什么的,这些是用于将程序下载到 msp 中吗?我也不确定 PJ.2 引脚(功能禁用)。
我知道它有很多要读的东西,但我对这个项目的时间真的很短,而且我没有太多时间去研究所有的东西。因此,如果您能阅读代码并帮助我将功能实现到代码中,我将非常高兴。
这是我想知道我是否这样做的代码:
#include <msp430.h>
#include <intrinsics.h>
volatile unsigned int timerCount = 0; //defines the millisecond counter
volatile unsigned int normalPulse1=0; //defines another flag to indicates when 1 second has passed for normal pulse1
volatile unsigned int badPulse1=0;//defines another flag to indicates when 1 second has passed for bad pulse1
volatile unsigned int normalPulse2=0; //defines another flag to indicates when 1 second has passed for normal pulse2
volatile unsigned int badPulse2=0;//defines another flag to indicates when 1 second has passed for bad pulse2
int main(void) {
WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer
P2OUT &= ~(BIT4); //preload 1pps to '0'
// set I/O pins directions
P1DIR |=BIT6+BIT7; //set p1.x to 11000000
P2DIR |=BIT4; // Set P2.4 to output direction
PJDIR |=BIT0+BIT1+BIT3; // set pj.x output 0000 1011
P2SEL |= BIT4; //select the option of using TD0.0 in pin 2.4
P2IES |= BIT4; // high -> low is selected with IES.x = 1.
P2IFG &= ~(BIT4); // To prevent an immediate interrupt, clear the flag for
// P1.3 before enabling the interrupt.
P2IE |= BIT4; // Enable interrupts for P2.4
// Configure XT1 (external oscillator)
PJSEL |= BIT4+BIT5; // port select for xt1
UCSCTL6 &= ~(XT1OFF); //xt1 is on
UCSCTL3 = 0; // FLL REFERENCE CLOCK REFERENCE = XT1
// configure TD0.0 to output of 1 pulse per second
TD0CTL0 |=MC_1+ID_3+TDSSEL_0+TDIE+CNTL_0+TDCLR; //defining timer d TD0.0 (P2.4)
TD0CCR0=1600-1; // setting TAR count up value 1600 (12.8MHz / 8 = 1.6MHz , 1.6MHz / 1600 = 1000 Hz) when 1000 is passed means 1 second has passed as well
TD0CCTL0 |= CCIE; //ENABLES CCIFG INTERUPT ON CCR0
__enable_interrupt();
for(;;){ // main loop (looping forever)
// EXTERNAL / INTERNAL SELECTION BY SW4
if ((P2IN & BIT2)==0){ // INTERNAL MODE
PJOUT |=BIT3; // sends '1' from pj.3 output to the multiplexer U4 (uses the internal 1pps)
//PULSE 1 : DESCRETE ON/OFF AND SWITCH ON/BAD/OFF
if ((P2IN & BIT0)==0 || (P1IN & BIT0)==0) { //NORMAL SIGNAL OF 1PPS checks if descrete source is on or 1pps sw pulse 1 is on
P1OUT |= BIT6; //ENABLES PULSE BY THE 'AND' GATE
PJOUT |= BIT0; //ENABLES TTL TO RS232 CONVERTER (FOR DIFF OUTPUT)
if(normalPulse1==1){ //checks if normalPulse1 is on from the ISR
normalPulse1 =0; // sets normalPulse1 to 0 again so the ISR will generate the pulse
P2OUT ^=BIT4; //generates 1pps out of p2.4
}
}
else {
P1OUT |= ~(BIT6); //DISABLES PULSE BY SENDING A '0' TO THE AND GATE
}
if ((P1IN & BIT2)==0) { //PULSE 1 BAD SIGNAL checks if the 1pps sw bad pulse is on
P1OUT |= BIT6; //ENABLES PULSE BY THE 'AND' GATE
PJOUT |= BIT0; //ENABLES TTL TO RS232 CONVERTER (FOR DIFF OUTPUT)
if(badPulse1==1){ //checks if badPulse1 is on from the ISR
badPulse1=0; // sets badPulse1 to 0 again so the ISR will generate the pulse
P2OUT ^=BIT4; //generates 1pps out of p2.4
}
}
//PULSE 2 : DESCRETE ON/OFF AND SWITCH ON/BAD/OFF
if ((P2IN & BIT1)==0 || (P1IN & BIT0)==0){ //NORMAL SIGNAL OF 1PPS checks if descrete source is on or 1pps sw pulse 2 is on
P1OUT |= BIT7; //ENABLES PULSE BY THE 'AND' GATE
PJOUT |= BIT1; //ENABLES TTL TO RS232 CONVERTER (FOR DIFF OUTPUT)
if(normalPulse2==1){
normalPulse2=0; // sets normalPulse2 to 0 again so the ISR will generate the pulse
P2OUT ^=BIT4; //generates 1pps out of p2.4
}
}
else {
P1OUT |= ~(BIT7); //DISABLES PULSE BY SENDING A '0' TO THE AND GATE
}
if ((P1IN & BIT3)==0){ //PULSE 2 BAD SIGNAL
P1OUT |= BIT6; //ENABLES PULSE BY THE 'AND' GATE
PJOUT |= BIT0; //ENABLES TTL TO RS232 CONVERTER (FOR DIFF OUTPUT)
if(badPulse2==1){
badPulse2=0; // sets badPulse2 to 0 again so the ISR will generate the pulse
P2OUT ^=BIT4; //generates 1pps out of p2.4
}
}
}
else { //EXTERNAL MODE
PJOUT |= ~(BIT3); //sends '0' from pj.3 output to the multimplexer U4 (uses the external 1pps)
P1OUT |= BIT6; // ENABLES PULSE 1
P1OUT |= BIT7; //ENABLES PULSE 2
PJOUT |= BIT0; //ENABLES RS422 DIFF OUTPUT FOR PULSE 1
PJOUT |= BIT1; // ENABLES RS422 DIFF OUTPUT FOR PULSE 2
}
}
}
return 0;
//ISR FOR TIMERD0.0 - NORMAL PULSE 1 AND 2
#pragma vector = TIMER0_D0_VECTOR //GENERATES 1PPS EVERY 1s for normal pulse
__interrupt void TIMER0_D0 (void){
if (++timerCount > 500) { // checks if the incrementation of timerCount reaches 500 (means 1 second has passed)
timerCount = 0; // resets the millisecond counter to 0
normalPulse1 = 1; //once it reaches 1000 (1 second) normalPulse1 will be 1
normalPulse2=1; //once it reaches 1000 (1 second) normalPulse2 will be 1
}
P2IFG &= ~(BIT4); // clears the flAG
}
//ISR FOR TIMERD0.0 - BAD PULSE 1 AND 2
#pragma vector = TIMER0_D0_VECTOR //GENERATES 1pulse EVERY 2s (0.5Hz) for bad pulse
__interrupt void TIMER0_D0 (void){
if (++timerCount > 1000) { // checks if the incrementation of timerCount reaches 1000 (means 2 second has passed)
timerCount = 0; // resets the millisecond counter to 0
badPulse1=1; // once it reaches 2000( 2 seconds) the badPulse1 will be 1.
badPulse2=1; // once it reaches 2000( 2 seconds) the badPulse2 will be 1.
}
P2IFG &= ~(BIT4); // clears the flAG