Author Topic: Microcontrollers  (Read 2450 times)

felipe

  • Member
  • *****
  • Posts: 1011
  • Eagles are just great!
Re: Microcontrollers
« Reply #30 on: November 23, 2018, 01:09:44 PM »
Here it is a sample program:
Code: [Select]
.cseg
.org 0

.equ PORTB =0x18 ; Port b's output register.
.equ DDRB  =0x17 ; Port b's data direction
;  register.

ldi r17,0xff ; Configure port b as output.
out DDRB,r17

ldi r16,0x00 ; Init the counter.

lp:
out PORTB,r16 ; Put the count in port b.
inc r16

rjmp lp ; Infinite loop.

I want to explain a little just some instructions (and directives). Just like a service for those who want to get closer with assembly programming with a microcontroller... :idea:
LDI = LOAD IMMEDIATE
RJMP = RELATIVE JUMP
.CSEG = USE THE PROGRAM (FLASH) MEMORY FOR THIS PIECE OF CODE
.ORG  0= START THE PROGRAM EXECUTION IN ADDRESS 0 FROM PROGRAM MEMORY

...Isn't super fun?  :bgrin:
Felipe.

hutch--

  • Administrator
  • Member
  • ******
  • Posts: 5945
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: Microcontrollers
« Reply #31 on: November 23, 2018, 01:38:22 PM »
I have seen long ago people who wrote their own assembler for various non x86 hardware and it was usually because the instruction set is nowhere as complicated as the x86/64 sets. Where you have close matching between common mnemonics for a particular processor and the opcodes they represent, the task is not all that difficult as you have the logic,

mnemonic = opcode

and a method of keeping track of the arguments AND basically line numbers for each mnemonic.
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :biggrin:

AW

  • Member
  • *****
  • Posts: 1608
  • Let's Make ASM Great Again!
Re: Microcontrollers
« Reply #32 on: November 23, 2018, 06:51:11 PM »
In general it is easy to learn those RISC instruction sets. Not so easy for Arm because there are many variations and specificities, if you have a book make sure you do have the specific microprocessor available otherwise you are largely waisting your time.

Siekmanski

  • Member
  • *****
  • Posts: 1709
Re: Microcontrollers
« Reply #33 on: November 24, 2018, 01:36:09 AM »
Hi Filipe,

A "hello world" example for the Atmega, it's a blinking led. ( the Atmega88 runs on his max. with a 20 MHz crystal )
Included the whole project for AVR Studio and pictures to show the pin connections and a simple 5V voltage regulator.

Code: [Select]
;Siekmanski's led project

.include <m88def.inc>   ; Atmega88 definitions

.equ F_CPU = 20000000   ; Crystal = 20 MHz "cpu clock speed for Wacht-macro"
.include "_wachten.inc" ; Wacht-macro --> _Wacht_us 1000 == 1 milisecond, 1000000 == 1 second


.cseg                   ; Code Segment
.org 0x0000             ; Code load adres 0x0000

    rjmp    Init        ; Make Relative jump to Init Lable


Init:
    ldi     r16,low(RAMEND) ; Init STACK
    out     SPL,r16
    ldi     r16,high(RAMEND)
    out     SPH,r16

    ldi     r16,0b11111111  ; r16 = set all 8 pins as output
    out     DDRC,r16        ; Save in PORTC Data direction Register


Start:                   
    sbi     PORTC,PC5       ; set pin 28 (PC5) high ( led on )

    _Wacht_us 1000000       ; wait 1 second

    cbi     PORTC,PC5       ; led off

    _Wacht_us 1000000       ; wait 1 second

    rjmp    Start

Creative coders use backward thinking techniques as a strategy.

felipe

  • Member
  • *****
  • Posts: 1011
  • Eagles are just great!
Re: Microcontrollers
« Reply #34 on: November 24, 2018, 03:17:21 AM »
That's great siekmanski, thank you very much.  :icon14:
Felipe.

AW

  • Member
  • *****
  • Posts: 1608
  • Let's Make ASM Great Again!
Re: Microcontrollers
« Reply #35 on: November 24, 2018, 03:34:57 AM »
For people interested in more recent versions of Atmel Studio this is a snapshot of version 7, which is composed from a Visual Studio Isolated Shell. Very cool.


Siekmanski

  • Member
  • *****
  • Posts: 1709
Re: Microcontrollers
« Reply #36 on: November 28, 2018, 06:37:26 AM »
Build your own computer for less than $5.00 and play Music and Demo graphics on an Atmega88 microcontroller ($1.50)  8)

https://www.youtube.com/watch?v=sNCqrylNY-0

Linus Akesson shows you how to do it: http://www.linusakesson.net/scene/craft/
Creative coders use backward thinking techniques as a strategy.

felipe

  • Member
  • *****
  • Posts: 1011
  • Eagles are just great!
Re: Microcontrollers
« Reply #37 on: November 28, 2018, 11:24:26 PM »
 :greenclp: This guy is a genius. First i thought, sure he write all in c...but voila, all in assembly  :greensml: Amazing project.  :t
Felipe.

felipe

  • Member
  • *****
  • Posts: 1011
  • Eagles are just great!
Re: Microcontrollers
« Reply #38 on: November 28, 2018, 11:32:52 PM »
Ok, i was wrong. There are a few sources in c. But still is a great project.   :icon14:  :icon_mrgreen:
Felipe.