Difference between revisions of "6272 Embedded Controller I/Oktober 2016"
From Teknologisk videncenter
m (→MSP430) |
m |
||
(9 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
+ | |||
+ | =Quiz= | ||
+ | *[http://quiz.mercantec.dk/quiz.php?u852q769v-1309213759 Link til Embedded I quiz] | ||
=C= | =C= | ||
*[http://phy.ntnu.edu.tw/~cchen/pdf/ctutor.pdf ctutor.pdf] | *[http://phy.ntnu.edu.tw/~cchen/pdf/ctutor.pdf ctutor.pdf] | ||
*[[C programming]] (Local articles) | *[[C programming]] (Local articles) | ||
*[[Const and volatile type qualifiers]] | *[[Const and volatile type qualifiers]] | ||
+ | *[[ASC II|ASC-II tegnsættet]] | ||
+ | |||
=MSP430= | =MSP430= | ||
+ | *[[MSP430]] | ||
*[http://mars.tekkom.dk/data/MSP430/materialer/01.01.01%20-%20MSP430%20Introduktion%20kompendium.pdf MSP430 Introduktion] (Loads PDF) | *[http://mars.tekkom.dk/data/MSP430/materialer/01.01.01%20-%20MSP430%20Introduktion%20kompendium.pdf MSP430 Introduktion] (Loads PDF) | ||
<!-- | <!-- | ||
Line 11: | Line 17: | ||
=Opgaver= | =Opgaver= | ||
[[MSP430/MSP430G2 Serial 1 project]] | [[MSP430/MSP430G2 Serial 1 project]] | ||
+ | |||
+ | == Få stdio bibliotek til at virke == | ||
+ | ===UART_poll.c=== | ||
+ | Indsæt følgende nederst i UART_poll.c | ||
+ | <source lang=c> | ||
+ | int putchar( int charout ) { | ||
+ | cout( (char) charout ); | ||
+ | return(charout); | ||
+ | } | ||
+ | |||
+ | int getchar( void ) { | ||
+ | int charin; | ||
+ | charin = (int) cin(); | ||
+ | if ( (charin == 0x0d ) || (charin == 0x0a) ) { // CR or LF | ||
+ | putchar( 0x0d ); // Output CR+LF | ||
+ | putchar( 0x0a ); | ||
+ | return( 0x0a ); // Return LF | ||
+ | } else { // Else other character | ||
+ | putchar( charin ); | ||
+ | return( charin ); | ||
+ | } | ||
+ | } | ||
+ | </source> | ||
+ | ===UART_poll.h=== | ||
+ | Indsæt følgende linier nederst i UART_poll.h | ||
+ | <source lang=c> | ||
+ | extern int putchar( int charout ); | ||
+ | extern int getchar( void ); | ||
+ | </source> | ||
+ | ===Main.c=== | ||
+ | Indsæt følgende include sætning øverst i main.c | ||
+ | <source lang=c> | ||
+ | #include <stdio.h> | ||
+ | </source> | ||
+ | =Lysdioder port definitioner= | ||
+ | <source lang=c> | ||
+ | #define SMALL_BOARD // Using MSP430G2553 | ||
+ | //#define BIG_BOARD // Using MSP430F5529 | ||
+ | |||
+ | #ifdef SMALL_BOARD | ||
+ | unsigned char volatile * const PORT1SEL = (unsigned char *) 0x0026; | ||
+ | unsigned char volatile * const PORT1SEL2 = (unsigned char *) 0x0041; | ||
+ | unsigned char volatile * const PORT1IN = (unsigned char *) 0x0020; | ||
+ | unsigned char volatile * const PORT1OUT = (unsigned char *) 0x0021; | ||
+ | unsigned char volatile * const PORT1DIR = (unsigned char *) 0x0022; | ||
+ | #endif | ||
+ | #ifdef BIG_BOARD | ||
+ | unsigned char volatile * const PORT1SEL = (unsigned char *) 0x020a; | ||
+ | unsigned char volatile * const PORT1IN = (unsigned char *) 0x0200; | ||
+ | unsigned char volatile * const PORT1OUT = (unsigned char *) 0x0202; | ||
+ | unsigned char volatile * const PORT1DIR = (unsigned char *) 0x0204; | ||
+ | unsigned char volatile * const PORT4SEL = (unsigned char *) 0x022b; | ||
+ | unsigned char volatile * const PORT4IN = (unsigned char *) 0x0221; | ||
+ | unsigned char volatile * const PORT4OUT = (unsigned char *) 0x0223; | ||
+ | unsigned char volatile * const PORT4DIR = (unsigned char *) 0x0225; | ||
+ | #endif | ||
+ | |||
+ | |||
+ | #ifdef SMALL_BOARD | ||
+ | *PORT1SEL &= ~(0x41); // Clear bit 1 and 6 | ||
+ | *PORT1SEL2 &= ~(0x41); // Clear bit 1 and 6 | ||
+ | *PORT1DIR |= 0x41; // Port 1 direction: bit 1 and 6 as output | ||
+ | *PORT1OUT &= ~0x01; // Port 1 bit 1=1 (Red LED on) bit 6 = 0 (Green LED off) | ||
+ | |||
+ | while(1) { | ||
+ | { | ||
+ | for( tmp=0; tmp <= 50000 ; tmp++); | ||
+ | *PORT1OUT ^= 0x41; // Invert port 1 bit 1 (RED) and bit 6 (GREEN) | ||
+ | if ( *PORT1IN | ||
+ | } | ||
+ | } | ||
+ | #endif | ||
+ | #ifdef BIG_BOARD | ||
+ | *PORT1SEL &= ~(0x01); // Clear bit 1 | ||
+ | *PORT1DIR |= 0x01; // Port 1 direction: bit 1 as output | ||
+ | *PORT1OUT |= 0x01; // Port 1 bit 1=1 (Red LED on) | ||
+ | *PORT4SEL &= ~(0x80); | ||
+ | *PORT4DIR |= 0x80; | ||
+ | *PORT4OUT &= ~(0x80); | ||
+ | while(1) { | ||
+ | { | ||
+ | for( tmp=0; tmp <= 50000 ; tmp++); | ||
+ | *PORT1OUT ^= 0x1; // Invert port 1 bit 1 (RED) | ||
+ | *PORT4OUT ^= 0x80; // Invert port 5 bit 8 (GREEN) | ||
+ | } | ||
+ | } | ||
+ | #endif | ||
+ | |||
+ | |||
+ | </source> | ||
+ | =STRIN eksempel= | ||
+ | <source lang=c> | ||
+ | |||
+ | #define ENTER 13 | ||
+ | #define NULL 0 | ||
+ | unsigned int strin( unsigned char *buf, int sizeofbuf ) { | ||
+ | int i = -1; // så vi starter på 0 | ||
+ | |||
+ | |||
+ | if ( sizeofbuf == 0) { // hvis intet return 0 | ||
+ | return(0); | ||
+ | } | ||
+ | |||
+ | sizeofbuf--; | ||
+ | |||
+ | do | ||
+ | { | ||
+ | i++; | ||
+ | buf[i] = cin(); | ||
+ | cout(buf[i]); | ||
+ | } while ((buf[i] != ENTER) && (i < sizeofbuf--)); // if enter is not and sizeobuf is less then 20, set last to null | ||
+ | buf[i]=NULL; | ||
+ | return (i); | ||
+ | } | ||
+ | </source> | ||
[[Category:Embedded]] | [[Category:Embedded]] |
Latest revision as of 08:49, 14 October 2016
Contents
Quiz
C
- ctutor.pdf
- C programming (Local articles)
- Const and volatile type qualifiers
- ASC-II tegnsættet
MSP430
- MSP430
- MSP430 Introduktion (Loads PDF)
Opgaver
MSP430/MSP430G2 Serial 1 project
Få stdio bibliotek til at virke
UART_poll.c
Indsæt følgende nederst i UART_poll.c
int putchar( int charout ) {
cout( (char) charout );
return(charout);
}
int getchar( void ) {
int charin;
charin = (int) cin();
if ( (charin == 0x0d ) || (charin == 0x0a) ) { // CR or LF
putchar( 0x0d ); // Output CR+LF
putchar( 0x0a );
return( 0x0a ); // Return LF
} else { // Else other character
putchar( charin );
return( charin );
}
}
UART_poll.h
Indsæt følgende linier nederst i UART_poll.h
extern int putchar( int charout );
extern int getchar( void );
Main.c
Indsæt følgende include sætning øverst i main.c
#include <stdio.h>
Lysdioder port definitioner
#define SMALL_BOARD // Using MSP430G2553
//#define BIG_BOARD // Using MSP430F5529
#ifdef SMALL_BOARD
unsigned char volatile * const PORT1SEL = (unsigned char *) 0x0026;
unsigned char volatile * const PORT1SEL2 = (unsigned char *) 0x0041;
unsigned char volatile * const PORT1IN = (unsigned char *) 0x0020;
unsigned char volatile * const PORT1OUT = (unsigned char *) 0x0021;
unsigned char volatile * const PORT1DIR = (unsigned char *) 0x0022;
#endif
#ifdef BIG_BOARD
unsigned char volatile * const PORT1SEL = (unsigned char *) 0x020a;
unsigned char volatile * const PORT1IN = (unsigned char *) 0x0200;
unsigned char volatile * const PORT1OUT = (unsigned char *) 0x0202;
unsigned char volatile * const PORT1DIR = (unsigned char *) 0x0204;
unsigned char volatile * const PORT4SEL = (unsigned char *) 0x022b;
unsigned char volatile * const PORT4IN = (unsigned char *) 0x0221;
unsigned char volatile * const PORT4OUT = (unsigned char *) 0x0223;
unsigned char volatile * const PORT4DIR = (unsigned char *) 0x0225;
#endif
#ifdef SMALL_BOARD
*PORT1SEL &= ~(0x41); // Clear bit 1 and 6
*PORT1SEL2 &= ~(0x41); // Clear bit 1 and 6
*PORT1DIR |= 0x41; // Port 1 direction: bit 1 and 6 as output
*PORT1OUT &= ~0x01; // Port 1 bit 1=1 (Red LED on) bit 6 = 0 (Green LED off)
while(1) {
{
for( tmp=0; tmp <= 50000 ; tmp++);
*PORT1OUT ^= 0x41; // Invert port 1 bit 1 (RED) and bit 6 (GREEN)
if ( *PORT1IN
}
}
#endif
#ifdef BIG_BOARD
*PORT1SEL &= ~(0x01); // Clear bit 1
*PORT1DIR |= 0x01; // Port 1 direction: bit 1 as output
*PORT1OUT |= 0x01; // Port 1 bit 1=1 (Red LED on)
*PORT4SEL &= ~(0x80);
*PORT4DIR |= 0x80;
*PORT4OUT &= ~(0x80);
while(1) {
{
for( tmp=0; tmp <= 50000 ; tmp++);
*PORT1OUT ^= 0x1; // Invert port 1 bit 1 (RED)
*PORT4OUT ^= 0x80; // Invert port 5 bit 8 (GREEN)
}
}
#endif
STRIN eksempel
#define ENTER 13
#define NULL 0
unsigned int strin( unsigned char *buf, int sizeofbuf ) {
int i = -1; // så vi starter på 0
if ( sizeofbuf == 0) { // hvis intet return 0
return(0);
}
sizeofbuf--;
do
{
i++;
buf[i] = cin();
cout(buf[i]);
} while ((buf[i] != ENTER) && (i < sizeofbuf--)); // if enter is not and sizeobuf is less then 20, set last to null
buf[i]=NULL;
return (i);
}