sábado, 24 de febrero de 2018



ARM Cortex M course




  1.  From Assembler to RTOS

If you are interested in the online course please write to the email below:
(Si estas interesado en el curso en linea contactanos al correo de abajo). 
postgraduatecahg@gmail.com 
Dr. Carlos Hernadez.


Syllabus 2018
1. Introduction.
2. Architecture.
  a. Registers.
  b. Instruction set.
3. Introduction to keil Uvision
4. I/O Configuration.
a. PORT F.
b. PORT A.
c. PORT B.
6. PLL.
7. Serial communication RS-232.
8. ADC.
9. SPI and DAC.
10. TIMERS.
11. Interrupts.
11. TIMER interrupt.
12. Introduction to RTOS.

viernes, 23 de febrero de 2018



PORTB & Seven Segment Display




Thus the PORTB.0 is going to be a
PORTB.1 is the b terminal and so on.



Display
a
b
c
d
e
f
g
0
1
1
1
1
1
1
0
1
0
1
1
0
0
0
0
2
1
1
0
1
1
0
1
3
1
1
1
1
0
0
1
4
0
1
1
0
0
1
1
5
1
0
1
1
0
1
1
6
1
0
1
1
1
1
1
7
1
1
1
0
0
0
0
8
1
1
1
1
1
1
1
9
1
1
1
1
0
1
1
--------------------------------------------------------------------------------------------------------------------------


#include "TM4C123.h"                    // Device header

// begins the definition of the registers of Port B to be used as a GPIO
#define SYSCTL_RCGC2_R     (*((volatile unsigned long *)0x400FE108))
#define GPIO_PORTB_PCTL_R  (*((volatile unsigned long *)0x4000552C))
#define GPIO_PORTB_AMSEL_R (*((volatile unsigned long *)0x40005528))
#define GPIO_PORTB_DIR_R   (*((volatile unsigned long *)0x40005400))
#define GPIO_PORTB_AFSEL_R (*((volatile unsigned long *)0x40005420))
#define GPIO_PORTB_DEN_R   (*((volatile unsigned long *)0x4000551C))
#define GPIO_PORTB_DATA_R  (*((volatile unsigned long *)0x400053FC))
// ends the definition of the registers of Port B

// begins the definition of the registers of Port F to be used as a GPIO
#define GPIO_PORTF_DATA_R       (*((volatile unsigned long *)0x400253FC))
#define GPIO_PORTF_DIR_R        (*((volatile unsigned long *)0x40025400))
#define GPIO_PORTF_AFSEL_R      (*((volatile unsigned long *)0x40025420))
#define GPIO_PORTF_PUR_R        (*((volatile unsigned long *)0x40025510))
#define GPIO_PORTF_DEN_R        (*((volatile unsigned long *)0x4002551C))
#define GPIO_PORTF_LOCK_R       (*((volatile unsigned long *)0x40025520))
#define GPIO_PORTF_CR_R         (*((volatile unsigned long *)0x40025524))
#define GPIO_PORTF_AMSEL_R      (*((volatile unsigned long *)0x40025528))
#define GPIO_PORTF_PCTL_R       (*((volatile unsigned long *)0x4002552C))
#define SYSCTL_RCGC2_R          (*((volatile unsigned long *)0x400FE108))
// ends the definition of the registers of Port F


int i=0;

void PortB_Init(void);
void delay(unsigned long halfsecs);

int main()
{
char x [] = {0x3F, 0x06, 0x5B, 0x4F, 0x66, 0x6D, 0x7D, 0x07, 0x7F, 0x6F};

PortB_Init();

while(1)
{

for(i = 0; i < 10; i++)
{
GPIO_PORTB_DATA_R |= x[i];
delay(5);
GPIO_PORTB_DATA_R &= 0x00;
}

}
}


void PortB_Init(void){
volatile unsigned long delay;
SYSCTL_RCGC2_R |= 0x00000002; //1) activate clock for Port B
delay = SYSCTL_RCGC2_R; //allow time for clock to start
GPIO_PORTB_AMSEL_R &= ~0xFF; // 3) disable analog on PA5
GPIO_PORTB_PCTL_R &= ~0xFFFFFFFF; // 4) PCTL GPIO on PA5
GPIO_PORTB_DIR_R |= 0xFF; // 5) direction PortB output
GPIO_PORTB_AFSEL_R &= ~0xFF; // 6) PB regular port function
GPIO_PORTB_DEN_R |= 0xFF; // 7) enable the PB as a digital port
}

void delay(unsigned long halfsecs){
  unsigned long count;

  while(halfsecs > 0 ) { // repeat while there are still halfsecs to delay
    count = 1538460; // 400000*0.5/0.13 that it takes 0.13 sec to count down to zero
    while (count > 0) {
      count--;
    } // This while loop takes approximately 3 cycles
    halfsecs--;
  }
}

















Write a program to add ten numbers from 0 to 10 or Convert following C language to ARM assembly Language.

void main()
{
int sum;
int i;
sum =0;
  for (i=0;i <10;i++)
  {
  sum = sum +1;
  }
}
--------------------------------------------

AREA myData, DATA
COUNT EQU 10  ; we will test count upto 10
SUM   EQU
  AREA MYCODE, CODE
  ENTRY
  EXPORT __main
__main
  LDR r0,=COUNT
  LDR r1, =SUM
  LDR r2, =1  ;r2 stores the initial vale of i Myloop
myloop
  ADD r1, r2, r1  ;sum = i + sum
  SUBS r3, r0, r2 ; r3 = r0-r2 (check if r0 and r2 are equal)
  BEQ stop  ;Branch to stop label if r0-r2=0, Z=1
  ADD r2, r2, #1  ; increment i
  BNE myloop  ; if flag not set then do the loop again
stop 
  B stop
  END

sábado, 3 de febrero de 2018





Convert the following C code to ASM for the ARM Cortex M4
-------------------------------------


void main ()
{
if (R1 ==R2)
  {
  R3 = R4 - R5;
  }
else if (R1>R2)
  {
  R3 =R4 + R5;
}
}



__main
  MOV r1,#2
  MOV r2,#1
  MOV r3,#1
  MOV r4,#1
  MOV r5,#1
COM
  CMP R1, R2    ;R1-R2 and set the flag
  SUBEQ R3, R4, R5  ; SUB if R1 = R2 it means that Z flag is 1
  ADDGT R3, R4, R5  ; ADD if R1 > R2 it means that C flag is 1
  B COM  ;JUMP to COM address

  END











MOVW and MOVT


Dr. C. A. Hernandez-Gutierrez


--------------------------------------------
if you want to load a 32 bits value you should to write MOVW followed by MOVT. Where MOVT is move TOP.

MOVW writes the less significant 16 bits of a register.
for example :
MOVW R0, #0xAAAA
it means that R0 = 0x0000AAAA
MOVT means MOV TOP 
for example:
MOVT R0, 0xFFFF
it means that R0 = FFFF0000

Finally, we share an example:


--------------------------------------------

main
  MOV R3,#0
  MOVW R3, #0xABCD  ;MOV Wide
  MOVT R3, #0xFFFF  ;MOV TOP
  B main  ;JUMP to main address

  END
--------------------------------------------
After the program finish R3 is going to be:
R3 = 0xFFFFABCD


--------------------------------------------

viernes, 2 de febrero de 2018



Convert the following C code to ASM for the ARM Cortex M4


-------------------------------------------------------------------
if (R0 ==R1)
  {
  R2 = R3 + R4;
  }

--------------------------------------------------------------------
AREA MYCODE, CODE
  ENTRY
  EXPORT __main
 
__main
  MOV r0,#1
  MOV r1,#1
  MOV r2,#5
  MOV r3,#5
  MOV r4,#1
COMPARATION
  CMP r0, r1
  ADDEQ r2, r3, r4
  B COM
  END

jueves, 1 de febrero de 2018


First program in assembler using Keil and ARM Cortex M4
(It is important to say that it is compatible with  Cortex M3)

Description: In general, this program moves immediate data to registers R0 and R1 and subsequently adds them.
The idea is that you can easily copy the code in Keil and do the respective debugging.

Any question please let me know.
If you want help with a project, a course or consultancy please contact me.
--------------------------------------------------------------------------------------------------------------------------

AREA MYCODE, CODE
  ENTRY
  EXPORT main
main
  MOV r0, #11
  MOV r1, #1
  ADD r2, r1, r0
  B main
  END
--------------------------------------------------------------------------------------------------------------------------
AREA
The AREA directive instructs the assembler to assemble a new code or data section. Sections are independent, named, indivisible chunks of code or data that are manipulated by the linker.
Syntax
AREA sectionname{,attr}{,attr}...

AREA Example,CODE, READONLY; An example code section. ; code

ENTRY
The ENTRY directive declares an entry point to a program.
Syntax
ENTRY
Usage
You must specify at least one ENTRY point for a program. If no ENTRY exists, a warning is generated at link time.
You must not use more than one ENTRY directive in a single source file. Not every source file has to have an ENTRY directive. If more than one ENTRY exists in a single source file, an error message is generated at assembly time.
Example
AREA ARMex, CODE, READONLY
ENTRY ; Entry point for the application


http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0489e/Chdibhie.html




BTFSS INSTRUCTION  IN ASSEMBLER FOR PIC18F In this sample, we show that how to use a switch input to make an action. Remember that I...