diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9165ef3 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +**/*.elf +**/*.log +**/*.synctex.gz +**/*.aux +**/.vscode \ No newline at end of file diff --git a/lab3/Makefile b/lab3/Makefile new file mode 100644 index 0000000..410e506 --- /dev/null +++ b/lab3/Makefile @@ -0,0 +1,31 @@ +SOURCES = $(wildcard *.c) +EXEC = $(patsubst %.c, %.elf, $(SOURCES)) +DEVICE = msp430g2553 +INSTALL_DIR=$(HOME)/ti/msp430_gcc + +GCC_DIR = $(INSTALL_DIR)/bin +SUPPORT_FILE_DIRECTORY = $(INSTALL_DIR)/include + +CC = $(GCC_DIR)/msp430-elf-gcc +GDB = $(GCC_DIR)/msp430-elf-gdb + +#O0 works, O1 works, O2 doesn't -Os works +CFLAGS = -I $(SUPPORT_FILE_DIRECTORY) -mmcu=$(DEVICE) -Os -g +LFLAGS = -L $(SUPPORT_FILE_DIRECTORY) -T $(DEVICE).ld + +all: prog1 prog2 adc pwm + +prog1: prog1.c + $(CC) $(CFLAGS) $(LFLAGS) $? -o prog1.elf +prog2: prog2.c + $(CC) $(CFLAGS) $(LFLAGS) $? -o prog2.elf +adc: adc.c + $(CC) $(CFLAGS) $(LFLAGS) $? -o adc.elf +pwm: pwm.c + $(CC) $(CFLAGS) $(LFLAGS) $? -o pwm.elf + +debug: all + $(GDB) ${EXEC} + +clean: + rm *.elf \ No newline at end of file diff --git a/lab3/adc.c b/lab3/adc.c new file mode 100644 index 0000000..e583cfe --- /dev/null +++ b/lab3/adc.c @@ -0,0 +1,49 @@ +//****************************************************************************** +// MSP430G2x31 Demo - ADC10, Sample A1, AVcc Ref, Set P1.0 if > 0.75*AVcc +// +// Description: A single sample is made on A1 with reference to AVcc. +// Software sets ADC10SC to start sample and conversion - ADC10SC +// automatically cleared at EOC. ADC10 internal oscillator times sample (16x) +// and conversion. +// +// MSP430G2x31 +// ----------------- +// /|\| XIN|- +// | | | +// --|RST XOUT| +// | | +// | | +// | | +// | | +// | | +// input >---|P1.1/A1 P1.0|--> red Led onboard BIT0 +// | | +// | P1.2|--> yellow Led +// | P1.6|--> green Led onboard BIT6 +// +// +// D. Dang +// Texas Instruments Inc. +//****************************************************************************** +#include "msp430.h" + +void main(void) { + WDTCTL = WDTPW + WDTHOLD; // Stop WDT + ADC10CTL0 = ADC10SHT_2 + ADC10ON; // ADC10ON + ADC10CTL1 = INCH_1; // input A1 + ADC10AE0 |= 0x02; // PA.1 ADC option select + P1DIR |= 0x01; // Set P1.0 to output direction + + while (1) { + ADC10CTL0 |= ENC + ADC10SC; // Sampling and conversion start + while (ADC10CTL1 &ADC10BUSY); // ADC10BUSY? + if (ADC10MEM < 0x2FF) { + P1OUT &= ~0x01; // Clear P1.0 LED off + } else { + P1OUT |= 0x01; // Set P1.0 LED on + } + unsigned i; + for (i = 0xFFFF; i > 0; i--); // Delay + } +} +//****************************************************************************** diff --git a/lab3/cblink/Makefile b/lab3/cblink/Makefile new file mode 100644 index 0000000..2174849 --- /dev/null +++ b/lab3/cblink/Makefile @@ -0,0 +1,19 @@ +OBJECTS=main.o +DEVICE = msp430g2553 +INSTALL_DIR=$(HOME)/ti/msp430_gcc + +GCC_DIR = $(INSTALL_DIR)/bin +SUPPORT_FILE_DIRECTORY = $(INSTALL_DIR)/include + +CC = $(GCC_DIR)/msp430-elf-gcc +GDB = $(GCC_DIR)/msp430-elf-gdb + +#O0 works, O1 works, O2 doesn't -Os works +CFLAGS = -I $(SUPPORT_FILE_DIRECTORY) -mmcu=$(DEVICE) -Os -g +LFLAGS = -L $(SUPPORT_FILE_DIRECTORY) -T $(DEVICE).ld + +all: ${OBJECTS} + $(CC) $(CFLAGS) $(LFLAGS) $? -o main.elf + +debug: all + $(GDB) main.elf diff --git a/lab3/cblink/main.c b/lab3/cblink/main.c new file mode 100644 index 0000000..06c7677 --- /dev/null +++ b/lab3/cblink/main.c @@ -0,0 +1,37 @@ +#include + +volatile unsigned int i = 0; // Initialize variables. This will keep count of how many cycles between LED toggles + +int main(void) +{ + WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer. This line of code is needed at the beginning of most MSP430 projects. + // The watchdog timer can reset the device after a certain period of time. + + P1DIR |= 0x41; // P1DIR is a register that configures the direction (DIR) of a port pin as an output or an input. + + // To set a specific pin as output or input, we write a '1' or '0' on the appropriate bit of the register. + // P1DIR = + // Since we want to blink the on-board LEDs, we want to set the direction of Port 1, Pins 0 and 6 (P1.0, P1.6) as outputs + + // We do that by writing a 1 on the PIN0 and PIN6 bits of the P1DIR register + // P1DIR = 0100 0001 + // P1DIR = 0x41 <-- this is the hexadecimal conversion of 0010 0001 + for (;;) // This for-loop will cause the lines of code within to loop infinitely + { + + // P1OUT is the register which holds the status of the LEDs. + // '1' specifies that it's ON or HIGH, while '0' specifies that it's OFF or LOW + // Since our LEDs are tied to P1.0 and P1.6, we will toggle the appropriate bits in P1OUT + + for(i=0; i< 20000; i++){ // Delay between LED toggles. This for-loop will run until the condition is met. + if (i == 0) + P1OUT ^= 0x01; // toggle the red LED (P1.0) + if (i == 6000) + P1OUT ^= 0x40; // toggle the green LED (P1.6) + // You need to be a little careful with using for loops for time delays. Optimizing compilers will + // notice if nothing happens inside a loop, and simply omit the loop to speed up the code. + // here, we have some comparisons being done inside the loop, so the code runs as desired even if + // the compiler optimizes. + } + } +} diff --git a/lab3/cblink/main.o b/lab3/cblink/main.o new file mode 100644 index 0000000..ea195a4 Binary files /dev/null and b/lab3/cblink/main.o differ diff --git a/lab3/prog1.c b/lab3/prog1.c new file mode 100644 index 0000000..3ad38ef --- /dev/null +++ b/lab3/prog1.c @@ -0,0 +1,32 @@ +/* + * PHYS319 Lab3 Timing example in C + * + * Written by Ryan Wicks + * 16 January 2012 + * + * This program is a C version of the assembly program that formed part of lab 2. + * This is not the best way to implement timing, or to organize your code. + * It is simply one way. + * + * This will almost certainly not give exactly the same timing as the assembly + * program from lab 2, and the output assembly will also be very different, even + * though the task is similar. + */ + +#include + +void main(void) { + volatile unsigned int count; // You must declare your variables in C + // notice the label volatile. What happens if you remove this label? + WDTCTL = WDTPW + WDTHOLD; // Stop WDT + P1DIR = 0x41; // Set P1 output direction + P1OUT = 0x01; // Set the output + + while (1) { // Loop forever + count = 60000; + while(count != 0) { + count--; // decrement + } + P1OUT = P1OUT ^ 0x41; // bitwise xor the output with 0x41 + } +} diff --git a/lab3/prog2.c b/lab3/prog2.c new file mode 100644 index 0000000..64bf17d --- /dev/null +++ b/lab3/prog2.c @@ -0,0 +1,32 @@ +/* + * PHYS319 Lab 3 Interrupt Example in C + * + * Written by Ryan Wicks + * 16 Jan 2012 + * + * This program is a C version of the assembly program that formed part of + * lab 2. + * + * + */ +#include + +void main(void) { + WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer + P1DIR = 0xF7; // C does not have a convenient way of + // representing numbers in binary; use hex instead + P1OUT = 0x49; + P1REN = 0x08; // enable resistor + P1IE = 0x08; // Enable input at P1.3 as an interrupt + + _BIS_SR (LPM4_bits + GIE); // Turn on interrupts and go into the lowest + // power mode (the program stops here) + // Notice the strange format of the function, it is an "intrinsic" + // ie. not part of C; it is specific to this chipset +} + +// Port 1 interrupt service routine +void __attribute__ ((interrupt(PORT1_VECTOR))) PORT1_ISR(void) { + P1OUT ^= 0x41; // toggle the LEDS + P1IFG &= ~0x08; // Clear P1.3 IFG. If you don't, it just happens again. +} diff --git a/lab3/pwm.c b/lab3/pwm.c new file mode 100644 index 0000000..6d5d2d0 --- /dev/null +++ b/lab3/pwm.c @@ -0,0 +1,15 @@ +#include "msp430.h" + +void main(void) { + WDTCTL = WDTPW + WDTHOLD; // Stop WDT + + P1DIR |= BIT2; // P1.2 to output + P1SEL |= BIT2; // P1.2 to TA0.1 + + CCR0 = 1000-1; // PWM Period + CCTL1 = OUTMOD_7; // CCR1 reset/set + CCR1 = 250; // CCR1 PWM duty cycle + TACTL = TASSEL_2 + MC_1; // SMCLK, up mode + _BIS_SR(LPM0_bits); // Enter Low Power Mode 0 +} + diff --git a/labnotes/Lab 1 and 2.aux b/labnotes/Lab 1 and 2.aux deleted file mode 100644 index 925706b..0000000 --- a/labnotes/Lab 1 and 2.aux +++ /dev/null @@ -1,6 +0,0 @@ -\relax -\@writefile{toc}{\contentsline {section}{\numberline {1}Lab 1}{1}} -\@writefile{toc}{\contentsline {section}{\numberline {2}Lab 2}{3}} -\@writefile{toc}{\contentsline {subsection}{\numberline {2.1}Student Number}{3}} -\@writefile{toc}{\contentsline {subsection}{\numberline {2.2}Program 1}{4}} -\@writefile{toc}{\contentsline {subsection}{\numberline {2.3}Program 2}{4}} diff --git a/labnotes/Lab 1 and 2.log b/labnotes/Lab 1 and 2.log deleted file mode 100644 index e03b0bc..0000000 --- a/labnotes/Lab 1 and 2.log +++ /dev/null @@ -1,171 +0,0 @@ -This is pdfTeX, Version 3.14159265-2.6-1.40.18 (MiKTeX 2.9.6350 64-bit) (preloaded format=pdflatex 2018.1.7) 18 JAN 2018 18:16 -entering extended mode -**"./Lab 1 and 2.tex" -("Lab 1 and 2.tex" -LaTeX2e <2017-04-15> -Babel <3.10> and hyphenation patterns for 75 language(s) loaded. -("C:\Program Files\MiKTeX 2.9\tex\latex\base\article.cls" -Document Class: article 2014/09/29 v1.4h Standard LaTeX document class -("C:\Program Files\MiKTeX 2.9\tex\latex\base\size11.clo" -File: size11.clo 2014/09/29 v1.4h Standard LaTeX file (size option) -) -\c@part=\count79 -\c@section=\count80 -\c@subsection=\count81 -\c@subsubsection=\count82 -\c@paragraph=\count83 -\c@subparagraph=\count84 -\c@figure=\count85 -\c@table=\count86 -\abovecaptionskip=\skip41 -\belowcaptionskip=\skip42 -\bibindent=\dimen102 -) -(C:\Users\Anthony\AppData\Roaming\MiKTeX\2.9\tex\latex\listings\listings.sty -("C:\Program Files\MiKTeX 2.9\tex\latex\graphics\keyval.sty" -Package: keyval 2014/10/28 v1.15 key=value parser (DPC) -\KV@toks@=\toks14 -) -\lst@mode=\count87 -\lst@gtempboxa=\box26 -\lst@token=\toks15 -\lst@length=\count88 -\lst@currlwidth=\dimen103 -\lst@column=\count89 -\lst@pos=\count90 -\lst@lostspace=\dimen104 -\lst@width=\dimen105 -\lst@newlines=\count91 -\lst@lineno=\count92 -\lst@maxwidth=\dimen106 - -(C:\Users\Anthony\AppData\Roaming\MiKTeX\2.9\tex\latex\listings\lstmisc.sty -File: lstmisc.sty 2015/06/04 1.6 (Carsten Heinz) -\c@lstnumber=\count93 -\lst@skipnumbers=\count94 -\lst@framebox=\box27 -) -(C:\Users\Anthony\AppData\Roaming\MiKTeX\2.9\tex\latex\listings\listings.cfg -File: listings.cfg 2015/06/04 1.6 listings configuration -)) -Package: listings 2015/06/04 1.6 (Carsten Heinz) - -("C:\Program Files\MiKTeX 2.9\tex\latex\base\alltt.sty" -Package: alltt 1997/06/16 v2.0g defines alltt environment -) -(C:\Users\Anthony\AppData\Roaming\MiKTeX\2.9\tex\latex\preprint\fullpage.sty -Package: fullpage 1999/02/23 1.1 (PWD) -\FP@margin=\skip43 -) -("Lab 1 and 2.aux") -\openout1 = `"Lab 1 and 2.aux"'. - -LaTeX Font Info: Checking defaults for OML/cmm/m/it on input line 9. -LaTeX Font Info: ... okay on input line 9. -LaTeX Font Info: Checking defaults for T1/cmr/m/n on input line 9. -LaTeX Font Info: ... okay on input line 9. -LaTeX Font Info: Checking defaults for OT1/cmr/m/n on input line 9. -LaTeX Font Info: ... okay on input line 9. -LaTeX Font Info: Checking defaults for OMS/cmsy/m/n on input line 9. -LaTeX Font Info: ... okay on input line 9. -LaTeX Font Info: Checking defaults for OMX/cmex/m/n on input line 9. -LaTeX Font Info: ... okay on input line 9. -LaTeX Font Info: Checking defaults for U/cmr/m/n on input line 9. -LaTeX Font Info: ... okay on input line 9. -\c@lstlisting=\count95 -LaTeX Font Info: External font `cmex10' loaded for size -(Font) <12> on input line 10. -LaTeX Font Info: External font `cmex10' loaded for size -(Font) <8> on input line 10. -LaTeX Font Info: External font `cmex10' loaded for size -(Font) <6> on input line 10. -LaTeX Font Info: External font `cmex10' loaded for size -(Font) <10.95> on input line 27. -LaTeX Font Info: Try loading font information for OMS+cmr on input line 29. - ("C:\Program Files\MiKTeX 2.9\tex\latex\base\omscmr.fd" -File: omscmr.fd 2014/09/29 v2.5h Standard LaTeX font definitions -) -LaTeX Font Info: Font shape `OMS/cmr/m/n' in size <10.95> not available -(Font) Font shape `OMS/cmsy/m/n' tried instead on input line 29. - -[1 - -{C:/ProgramData/MiKTeX/2.9/pdftex/config/pdftex.map}] -Overfull \hbox (59.12425pt too wide) in paragraph at lines 74--74 -[] \OT1/cmtt/m/n/10.95 |_____| | |_____| | |_____| | -|_____| | | set manually[] - [] - - -Overfull \hbox (59.12425pt too wide) in paragraph at lines 74--74 -[] \OT1/cmtt/m/n/10.95 ______|SW| ______|SW| ______|SW| -______|SW| |__ w/ 5V|GND to[] - [] - - -Overfull \hbox (59.12425pt too wide) in paragraph at lines 74--74 -[] \OT1/cmtt/m/n/10.95 | GRD_|__| | GRD_|__| | GRD_|__| -| GRD_|__| | O| select digit[] - [] - - -Overfull \hbox (18.88344pt too wide) in paragraph at lines 74--74 -[] \OT1/cmtt/m/n/10.95 | | | -| |__| | |[] - [] - - -Overfull \hbox (18.88344pt too wide) in paragraph at lines 74--74 -[] \OT1/cmtt/m/n/10.95 | | | -| | | |[] - [] - - -Overfull \hbox (24.63213pt too wide) in paragraph at lines 74--74 -[] \OT1/cmtt/m/n/10.95 D3 D2 D1 -D0 STR A1 A0[] - [] - - -Overfull \hbox (24.63213pt too wide) in paragraph at lines 74--74 -[] \OT1/cmtt/m/n/10.95 11 10 01 -00 == A1 A0[] - [] - -[2] [3] -Overfull \hbox (53.37556pt too wide) in paragraph at lines 129--129 -[] \OT1/cmtt/m/n/10.95 xor.b #0x41, R8 ; #00000001b -> #0100 -0000b -> ... (LED1 -> LED2 -> ...)[] - [] - - -Overfull \hbox (53.37556pt too wide) in paragraph at lines 131--131 -[] \OT1/cmtt/m/n/10.95 mov.w #40000, R10 ; counts to decrement - (2nd dec, since max val is 65536)[] - [] - -[4] [5] [6] ("Lab 1 and 2.aux") ) -Here is how much of TeX's memory you used: - 1500 strings out of 493323 - 21431 string characters out of 3139061 - 81399 words of memory out of 3000000 - 5086 multiletter control sequences out of 15000+200000 - 8979 words of font info for 32 fonts, out of 3000000 for 9000 - 1141 hyphenation exceptions out of 8191 - 26i,6n,32p,754b,219s stack positions out of 5000i,500n,10000p,200000b,50000s - - -Output written on "Lab 1 and 2.pdf" (6 pages, 129657 bytes). -PDF statistics: - 61 PDF objects out of 1000 (max. 8388607) - 0 named destinations out of 1000 (max. 500000) - 1 words of extra memory for PDF output out of 10000 (max. 10000000) - diff --git a/labnotes/Lab 1 and 2.synctex.gz b/labnotes/Lab 1 and 2.synctex.gz deleted file mode 100644 index 685dfcb..0000000 Binary files a/labnotes/Lab 1 and 2.synctex.gz and /dev/null differ