Report Lab 1

March 25, 2018 | Author: Phuc Nguyen Thai Vinh | Category: Software Engineering, Office Equipment, Digital Electronics, Software, Software Development


Comments



Description

Report Lab 1Set up for ‘printf’ to work with Msp430: For the first program: “hello world” /* Names: Nguyen Thai Vinh Phuc Hoang Duc Nghia Class: Group: */ #include #include 10ECE Group 6 <stdio.h> <msp430.h> /* * hello.c */ int main(void) { } WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer to see hello world printf("Hello World!\n"); //} return 0; } return 0.c */ int main(void) { // WDTCTL = WDTPW | WDTHOLD.h> <msp430.)// infinite loop { printf("Hello World!\n").h> /* * hello..For the first program: “hello world” with loop /* Names: Nguyen Thai Vinh Phuc Hoang Duc Nghia Class: Group: */ #include #include 10ECE Group 6 <stdio. // Stop watchdog timer so the for(. } For assembling code(sample blinking 1 ) . // Stop watchdog timer WDTCTL = WDTPW + WDTHOLD. Group 6 . Decrement R7 .SP . P2. Assemble into program memory . Delay over? .LIST.delay R7 //0x0005 for checking debug funtion .2 Wait L1 mov..sect ". Include device header file . Toggle P2. Stop watchdog timer SetupP1 bis. define entry point START mov.short START .w #WDTPW+WDTHOLD.&P2OUT .cdecls C.global _START . Initialize 0x1200 StopWDT mov.text .end . "msp430fg4618.&WDTCTL.&P2DIR .----------------------------------------------------------------------.h" . Again .b #004h.reset" .b #004h. the location of program C is in program flash memory where the instructions are located.w R7 jnz L1 jmp Mainloop . .----------------------------------------------------------------------. MSP430 RESET Vector As seen below.R7 dec.w #0x300.Name: GROUP 6: NGUYEN THAI VINH PHUC && HOANG DUC NGHIA .2 direction = 1 Mainloop xor.w #0xA000. .As seen below. debugging a program is the Register window. Build the project and then debug this project. For R7=0x0005.5. Modify the assembly language program to load a value of 0x0005 into register R7. Then press F5 to go step by step for debug. Next. trace through each line of the code using the Step Into option observing the register values as each line of code is executed. In particular. take note how R7 starts with a value 0x0005 and decreases in value until it reaches zero. . . . . For the next second.1. . the green LED is on and the yellow LED is off. For one second. Adjust the value used in the delay loop to obtain the correct timing. An additional for loop may be needed to obtain the desired timing. Make sure to have the lab assistant verify the functionality of this program. Make sure that this program is properly commented. Modify and execute the C-language program so that both the green and yellow LEDs blink alternatively on and off about once every second. the green LED is off and the yellow LED is on. // Set port 2 bit 1 to as an XANH // output. the green LED is on and the yellow LED is off. //For one second. // Stop watchdog timer so the // program // runs indefinitely P2DIR |= 0x06./* Names: Class: Group: */ Nguyen Thai Vinh Phuc Hoang Duc Nghia 10ECE Group 6 //#include <msp430.// 1 second approximately P2OUT = P2OUT ^ 0x06.h" //#include "stdio. FLASH at 0x3100 – // 0xfbff // Port 2 is used for the LED's Port 2 bit 2 is the green LED.h" /* * main.i++).){ // delay before turning changing the state of the LED for(i=0. // Port 2 bit 1 is the yellow LED // input buttons on port 1 bits SW1 = bit 0 and SW2 = Bit2 // 1 = SW not pressed 0 = pressed //********************************************************************* //--------------------------------------------------------------------// must include the C header to get the predefined variable names // used by the MSP430FG4618 on the experimenter board //--------------------------------------------------------------------#include "msp430fg4618. 1 = output 0 = input // turn the light on // set initial led for green and yellow led //Port 2 bit 2 is the green LED and Port 2 bit 1 is the yellow LED P2OUT=0x04.h> //********************************************************************* // LED turn on and off to blink the LED on Port 2 of the MSP430FG4618 // experimenter board RAM at 0x1100 . WDTCTL = WDTPW + WDTHOLD.i<=10000.c */ int main(void) { // tell the compiler not to optimize the variable I.. otherwise the // compiler may change how the variable is used volatile unsigned int i. for initial condition // go run the program forever for (.0x30ff. // X xor 1 =!x } } . Green: For the delay: .Press F5 to go step by step for seeing what happens inside registers. but this time modify and execute the assembly language program. For debug: R7: 0005h Press F5 to go step by step for seeing what happens inside registers. An additional loop may be needed to obtain the desired timing for second on and one second off. Repeat step 1.Yellow: 2. . ----------------------------------------------------------------------.w #0x300. Initialize 0x1200 or StopWDT mov.short START .w #WDTPW+WDTHOLD.cdecls C..Name: GROUP 6: NGUYEN THAI VINH PHUC && HOANG DUC NGHIA .w R7 jnz L1 xor.&P2OUT .&P2OUT . Include device header file .&P2DIR . Delay over? . Decrement R7 . Stop watchdog timer SetupP1 bis.delay R7 //0x0005 for checking debug funtion .sect ". Red off main mov.2 direction = 1 SetupP2 mov.text .----------------------------------------------------------------------. Green ON.R7 L1 dec.h" . define entry point START mov.w #0x0005.Group 6 .b #0x06.reset" . Again .&WDTCTL .LIST.b #0x04. "msp430fg4618.b #0x06.global _START .end Green . MSP430 RESET Vector .SP . P2. Assemble into program memory . jmp main . . Yellow . . "msp430fg4618.&WDTCTL .R7 L1 dec.2 direction = 1 SetupP2 mov. Initialize 0x1200 or StopWDT mov. Assemble into program memory .Name: GROUP 6: NGUYEN THAI VINH PHUC && HOANG DUC NGHIA . Again . Decrement R7 .w #0x300. Delay over? .cdecls C.delay R7 //0x0005 for checking debug funtion .text .short START .----------------------------------------------------------------------. the location of program C is in program flash memory where the instructions are located.&P2OUT .Group 6 .b #0x06. define entry point START mov.----------------------------------------------------------------------..w #WDTPW+WDTHOLD. Include device header file . MSP430 RESET Vector As seen below.&P2OUT .&P2DIR . jmp main .end . Green ON.w #0xA000. Stop watchdog timer SetupP1 bis.reset" .LIST.SP .sect ". P2.b #0x06. Red off main mov.h" .b #0x04.global _START .w R7 jnz L1 xor. For msp430fg4618: /* Names: Nguyen Thai Vinh Phuc Hoang Duc Nghia Class: 10ECE Group: Group 6 */ //********************************************************************* // LED turn on and off to blink the LED on Port 2 of the MSP430FG4618 // experimenter board RAM at 0x1100 . FLASH at 0x3100 – // 0xfbff // Port 2 is used for the LED's Port 2 bit 2 is the green LED. for (. // Set port 2 bit 1 to as an // output. // Stop watchdog timer so the P1DIR= 0x00.h" int main(void) { // tell the compiler not to optimize the variable I.3. // set port P1. Make sure that this program is properly commented. Execute this program and verify that it is running correctly.0x30ff. Make sure to have the lab assistant verify the functionality of this program. // both leds are off initially //Port 2 bit 2 is the green LED and Port 2 bit 1 is the yellow LED P2OUT=0x00.1 as input // runs indefinitely P2DIR |= 0x06.){ // go run the program forever // infinite loop for running program always if((P1IN&0xFF)==0x02) { //Green is On and Red is Off. 1 = output 0 = input P2OUT=0x00. otherwise the // compiler may change how the variable is used volatile unsigned int i.. WDTCTL = WDTPW + WDTHOLD. // Port 2 bit 1 is the yellow LED // input buttons on port 1 bits SW1 = bit 0 and SW2 = Bit2 // 1 = SW not pressed 0 = pressed //********************************************************************* //--------------------------------------------------------------------// must include the C header to get the predefined variable names // used by the MSP430FG4618 on the experimenter board //--------------------------------------------------------------------#include "msp430fg4618. Write a C-language program that turns on the green LED when SW1 on the experimenter board is pressed and the yellow LED when SW2 is pressed. SW1 is pressed .0 and P1. P2OUT=0x04. } else { P2OUT=0x00. are not pressed } } //Green is oFF and Red is Off } } } Press F5 to go step by step for seeing what happens inside registers. } else { if((P1IN&0xFF)==0x00) //Green is On and Red is Off { P2OUT=0x06. } else { and SW2 is pressed if((P1IN&0xFF)==0x01) //Green is off and Red is on { P2OUT=0x02. Green led is on and red led is off SW2 is pressed SW1 is pressed both 2 of witched . .Red led is on and Green led is off Both leds are off. ON MSP430G2231\ .Both leds are on. for (. P1OUT=0x00. } else { if((P1IN&0xFF)==0x16)//// Red is on and Green is on { P1OUT=0x41. // Red is off and Green is off } } } return 0.){ // Stop watchdog timer // Set P1.6 to output //initial RED and Green leds are off // program is online if((P1IN&0xFF)==0x1E) // Red is on and Green is off { P1OUT=0x01../* Names: Class: Group: */ Nguyen Thai Vinh Phuc Hoang Duc Nghia 10ECE Group 6 #include <msp430G2231.h> int main(void) { WDTCTL = WDTPW | WDTHOLD. direction volatile unsigned int i. } } Press F5 to go step by step for seeing what happens inside registers.0 and P1. } else { if((P1IN&0xFF)==0x06)// Red is off and Green is on { P1OUT=0x40. . } else { P1OUT=0x00. P1DIR |= 0x41. 4: general purpose) green .Second putton( P1. Red . .text ..4...... ..global main .... For ‘msp430fg4618.............h’ Button 1 is pressed and Green led on and Red led is off .....Group: Group 6 ...... define entry point ..cdecls C..."msp430fg4618.... . but this time writes an assembly language program to turn on and off the green and yellow LED’s .. the c header file .......-----------------------------------------------------------------------------.... ..............Class: 10ECE ....Names: Nguyen Thai Vinh Phuc .... cdecls tells assembler to allow ..... Repeat step 3........ program start .... Hoang Duc Nghia ......h" ..... Main Code .....................-----------------------------------------------------------------------------.....LIST.................... &P2OUT jmp mainloop . Interrupt Vectors . set input for switch 1 and 2 bis.b #0x00.&P2DIR . set P1.&P2OUT bit.&P1IN led(switch 2) jnz On off1 jmp mainloop off1 mov. set intial both of two leds off mainloop bit.end switch of yellow . make P1.b #0x02.&P2OUT bit. . read switch at P1.&P2OUT .main mov.-----------------------------------------------------------------------------. all others are inputs by default mov.1. stop watchdog timer mov.reset" . read switch at P1.-----------------------------------------------------------------------------.SP .b #0x00.b #0x01. Yellow on 01 .&P1DIR .6 output .0 00 . . address to start execution .&P1IN jz on2 . MSP430 RESET Vector .short main .sect ".w #0x300.&WDTCTL .b #0x04.&P1IN jnz mainloop .b #0x06.b #0x00. active low 00 hoac 0x .b #0x01.0 and P1. 00 mov. on2 xor.0 (red on) .Green is on . initialize stack pointer mov.b #0x02. jumpmain .w #WDTPW+WDTHOLD. Read SW1 switch of green led(switch 1) 11 . Status register: Green led off and Red led is on . Green led is on and Red led is on . Green led is off and Red led is off .
Copyright © 2024 DOKUMEN.SITE Inc.