Close

Blink with SDAS

A project log for Semyon

A small simon game using the 8 pin STC15F104W, written in 8051 assembly using the SDAS(ASXXXX) assembler from the SDCC toolchain.

hummusprinceHummusPrince 10/14/2019 at 20:102 Comments

So after I gathered enough information and examples for using SDAS, I gave it a shot.

The code should light the LEDs one after the other, then turn them off at the same order. The result came out something like this:

.module blink

.area INTV (ABS)
.org 0x0000
_int_reset:
	ljmp main

.area CSEG (ABS, CODE)
.org 0x0090
main:
	cpl P3.2
	acall delay
	cpl P3.3
	acall delay
	cpl P3.4
	acall delay
	cpl P3.5
	acall delay
	nop
	nop
	nop
	nop
	sjmp main
	
delay:
	mov r4, #0x00	
	mov r3, #0x00	
wait:
	djnz r4, wait
	djnz r3, wait
	ret

In the spirit of the usynth example, the areas are called INTV for interrupt vector and CSEG for the code segment. The code begins in address 0x90 as the interrupt vector address of INT4#, the farthest interrupt here, is 0x83.

I called the assembler in the command line:

sdas8051 blink.asm

 While my code had errors, it shouted errors at me. But once the code was functioning, nothing happened. No hex file has appeared, or other output file whatsoever.

"sdas8051 -h" to the rescue! By looking at possible flags, it looks like I want to add the flags -l, -o, and -s to generate list file, object file and symbol file accordingly:

sdas8051 -los blink.asm

Runnig this generated these files, but none are hex. It seems that there's a need for linking now - although there's only one file here. 

The linker is called SDLD, and it's flag list suggests that the -i flag generates an intel hex out of the arguments:

sdld -i semyon

This generated a .ihx format file. Looking at it, it looks like some gimp cousin of the intel .hex file with a weird extension. I'm not the only one who hates it, so a short google has showed me that SDCC has a utility called 'packihx' just to make these .ihx files into proper .hex files, mostly by ordering and aligning them.

Now that I have a blink.hex file I can finally download it to the chip! The lights indeed did their thing on and off, as I wanted them.

To ease the build, I made for semyon the crudest makefile you've ever seen:

build:
	sdas8051 -los semyon.asm
	sdld -i semyon
	packihx semyon.ihx > semyon.hex

Now that's I can use SDAS correctly, it's time to do write semyon's firmware! 

Discussions

David Hovemeyer wrote 12/13/2019 at 20:06 point

Thank you for posting this! I was looking for a simple example of using the sdcc tools to write assembly for the 8051. This is exactly what I was looking for.

  Are you sure? yes | no

HummusPrince wrote 12/14/2019 at 16:18 point

I'm happy to hear that it has helped you! Making the use of SDAS more feasible by creating examples was one of my motivations for this project :)

  Are you sure? yes | no