-
MSP430 C++ Hello World MSP430G2553
05/03/2018 at 04:25 • 0 commentsMSP430G2553 programming with a Hello World code. C++ on IAR Embedded Workbench.
Code here:
// Basic MSP430 Hello World
#include "msp430G2553.h"
#define G_LED BIT6
#define R_LED BIT0int i,j,delay;
void delay_time(int);
void delay_long(int);void main(void){
WDTCTL = WDTPW + WDTHOLD; // disable watch dog timer
DCOCTL = CALDCO_16MHZ; // set internal oscillator at 16MHz
BCSCTL1 = CALBC1_16MHZ; // set internal oscillator at 16MHzP1OUT = 0x00;
P2OUT = 0x00;
P1DIR = 0xFF; // Set all as outputs
P2DIR = 0xFF; // Set all as outputsfor(;;) {
P1OUT |= G_LED; // Enable = 1
delay_long(delay);
P1OUT &= ~(G_LED); // Disable = 0
delay_long(delay);
}
}//----------------------------------------------------------------------------------------------------------------------------------
//----------------- Functions & Procedures ----------- Functions & Procedures ----------- Functions & Procedures -------------
//----------------------------------------------------------------------------------------------------------------------------------void delay_time (int delay){ //----------------------------------------- Delay---------------------
do delay--;
while (delay != 0);
}void delay_long (int){ //--------------------------------------- Delay long------------------
int j;
j = 100;
do{
delay_time(5000);
j--;
}while (j != 0);
} -
ASM Hello World Program for PIC16F628 / PIC16F819
05/02/2018 at 05:51 • 0 commentsProgramming a PIC16F628 microcontroller using MPLABX and PICkit3 - A Hello World Program demonstrating the basic principles of writing a piece of ASM code. The LEDs on the PORTB are lighting up according to some pressed buttons on the PORTA used as an input here.
For details about the hardware used in this video, refer to the following website: www.funelectronicstoday.com
The result code, in case you want to copy-paste it:
; Hello world basic 16F628 ASM program
RESET CODE 0x00
#INCLUDE P16F628A.inc ; put angle brackets here
__CONFIG _HS_OSC & _CP_OFF & _LVP_OFF & _BODEN_OFF & _MCLRE_ON & _PWRTE_OFF & _WDT_OFF
; THIS PROGRAM WAS DESIGNED FOR 20 MHZ OSC
;------------------------------------
;_XT_OSC : EXTERNAL 4MHZ
;_HS_OSC : EXTERNAL 20MHZ
;_INTRC_OSC_NOCLKOUT : INTERNAL 4MHZ
;------------------------------------
CBLOCK 0X20 ; THIS IS HOW YOU DECLARE A BLOCK OF VARIABLES
NVAR1, NVAR2
ENDC
CLRF PORTA ;SET THESE PINS BEFORE YOU ACTUALLY CONFIGURE THEM
CLRF PORTB
MOVLW 0X07 ; DISABLE THE COMPARATORS AND ENABLING THE PINS FOR
MOVWF CMCON ; FUNCTIONING AS I-O
BCF STATUS, RP1 ;SETS BANK1
BSF STATUS, RP0 ;
MOVLW B'00111111' ;SET PINS 0 - 4 AS INPUTS ; TRIS 5 AS 1 ALWAYS
MOVWF TRISA
MOVLW 0X00 ;SET PINS 0 - 7 AS OUTPUTS
MOVWF TRISB
BCF STATUS, RP1 ;SETS BANK1
BCF STATUS, RP0 ;
;MAIN LOOP----------------REPEAT
MOVFW PORTA
MOVWF NVAR1
MOVFW NVAR1
MOVWF PORTB
GOTO REPEAT ; END OF MAIN LOOP
END -
Delay loop code in ASM PIC16F628 / PIC16F819
05/02/2018 at 05:46 • 0 commentsIn the previous videos I've been explaining how to initialize the ports of the PIC16f628 microcontroller. This other video shows how to write a delay loop and blink some LEDs for fun. The code of the main loop and of the delay loop is listed below in case you want to copy-paste it: Check also funelectronicstoday.com for more fun projects.
;MAIN LOOP----------------
REPEAT
MOVLW 0X00
MOVWF PORTB
CALL DELAY
MOVLW 0X01
MOVWF PORTB
CALL DELAY
MOVLW 0X02
MOVWF PORTB
CALL DELAY
MOVLW 0X04
MOVWF PORTB
CALL DELAY
MOVLW 0X08
MOVWF PORTB
CALL DELAY
CLRF PORTB
CALL DELAY
GOTO REPEAT ; END OF MAIN LOOP
DELAY
CLRF DELAY1
CLRF DELAY2DELAYLOOP
DECFSZ DELAY2,F
GOTO DELAYLOOP
DECFSZ DELAY1,F
GOTO DELAYLOOP
RETURN