ASM programming a PIC16F628 Hello World
Check the Logs area for the source code.
More ASM programming: How to make a delay loop and blink some LEDs
Check also the Logs for the source code.
MSP430 C++ Hello World
MSP430G2553
Tutorials and advice for those who are new in developing the MCU programming skills
To make the experience fit your profile, pick a username and tell us what interests you.
We found and based on your interests.
Check the Logs area for the source code.
Check also the Logs for the source code.
MSP430G2553
MSP430G2553 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 BIT0
int 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 16MHz
P1OUT = 0x00;
P2OUT = 0x00;
P1DIR = 0xFF; // Set all as outputs
P2DIR = 0xFF; // Set all as outputs
for(;;) {
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);
}
Programming 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
In 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 DELAY2
DELAYLOOP
DECFSZ DELAY2,F
GOTO DELAYLOOP
DECFSZ DELAY1,F
GOTO DELAYLOOP
RETURN
Create an account to leave a comment. Already have an account? Log In.
Become a member to follow this project and never miss any updates
About Us Contact Hackaday.io Give Feedback Terms of Use Privacy Policy Hackaday API Do not sell or share my personal information