New to K8048 and ASM

Hi, I have just bought and built my K8048 PIC programmer after playing with some PICs in university that I program using the BASIC language. Unfortunately I have no knowledge of assembly and so can not do much with this other than flash the demo program to it.

If possible could someone please point me to some specific tutorials or information on writing my own programs for this PIC, I think experimentation is the best way for me to start learning assembly.

Thanks

Most information can you find at the Microchip’s website, www.microchip.com.
You can find also on the net a lot of sample codes…

I have checked there but as I said, I have no prior knowledge of PIC programming/assembler. I am becoming confused with the different terms and names i am finding associated with it.

Is it absolutely necessary that i write code for my PIC in assembler? I hae seen what appeared to be PIC programs written in C. As I am familiar with both C,C# and C++, this would be easier for me.

Also I have seen two different versions of code claimingto be assembler. One written in what appears most definately to be assembler with a .ams file format, the other written in plain english (high level) with a .jal extension. Maybe someone could give more specific links to where i can get started? Thanks.

Absolutely not.
You may download a free Student Edition C compiler for PIC18 devices from Microchip.
microchip.com/stellent/idcpl … t=SW006011

For PIC10/12/14/16 devices you can download CC5X free edition from B Knudsen Data:
bknd.com/
Both C compilers you can run under the MPLAB IDE (Integrated Development Environmen):
microchip.com/stellent/idcpl … t=SW007002

Anyhow it is useful to know the Microchip assembly language. Both C compilers produce the assembly listing of the compiled code. It is in many cases very useful to check those files. (Note: In CC5X an additional command line option -CA must be set to get complete .asm file.)

Thank you for those. Are there any specific reads on assembler you would recommend, also can anyone answer my former questionh regarding why those languages appear different? I take it the .jal isn’t assember?

Here you’ll find more about the Jal:
voti.nl/jal/index_1.html

I have no experience in this Jal language.

One alternative C compiler is MikroC.
You may download the free demo version from:
mikroe.com/en/compilers/mikr … wnload.htm

There are very good documentations!
1st_project_pic_c.pdf etc.

Hmm, Apparently similar to Pascal, I think i would be best served by learning Assembler.

The only thing confusing me now is when i find code, how do I make it specific to my hardware, correct inputs outputs? What exactly do I use to reference those inputs and outputs? Hardware specific help for these kits you provide is slightly lacking. :frowning:

Download application notes to see some .asm code.
microchip.com/stellent/idcpl … 1=function

e.g. select “8-bit PIC® Microcontrollers”
then select PIC16

Very important: Download datasheet and read it. You can learn how all the registers have to be set to get I/O functions, timers, PWM, A/D converters etc. set properly and working OK.

Read also forum.microchip.com/
there are a lot of interesting topics.

e.g. MPLAB IDE
and see the thread: “help me using MPLAB IDE”
forum.microchip.com/tm.aspx?m=234968

That’s very helpful, thank you. Now i need to find somewhere I can learn the assembler language because all this stuff means nothing to me:

W    EQU   H'0000'
F    EQU   H'0000'

Also, all the register files, STATUS bits, RAM definition and configuration bits.

I also don’t quite understand in Variable definition is:

SW1     EQU    H'00'   ;SW1 is triggering RA0

which part of this specifically says this is defining an input and which part references RA0? I take it a 2bit hex value always refers to I/O or some such?

Thank you for your patience and helpfulness. My goal is to be able to write my own programs so I can make things using PICs. The googling I have done to find assembler tutorials have started too deep for me to understand any of it. Still searching for a real assembler for noobs tutorial.

This will help:
ww1.microchip.com/downloads/en/D … 33014J.pdf

Download the datasheet for the PIC you are using. There you’ll find the assembly instruction set and descriptions specific for that chip.

Ok, I have ad a brief read of this, and it’s very helpful with those instructions i don’t understand! I now know that this is the instruction set.

Does this mean that i can leave everything under: register files, STATUS bits, RAM definition and configuration bits the same and just start writing a new program? Should I even leave the “RESET; main boot routine” as is since my inputs and outputs are the same.

P.S. Is my PIC the midrange or baseline? Baseline uses 12bit path and midrange uses 14bit, just so I know which instruction set i should be paying attention to in that document. I am using PIC16F627 04-P that came with the kit.

You’ll find the datasheet for the PIC16F627 in the folder C:\PicProg2006\datasheet if you installed the programmer software in default folder.
See p. 111 “15.0 INSTRUCTION SET SUMMARY” .

Download the MPLAB IDE Quick Start Guide. There is a step by step instructions for your first PIC project.
ww1.microchip.com/downloads/en/D … 51281F.pdf

As a good starting point is the template file f627temp.asm. You only need to copy this file and the include file p16F627.inc to your project folder.
Then add the .asm file to the project and add your code to the “main” section and compile it. You get the .hex file to program the PIC.

You must set the configuration word according to your needs (oscillator etc.).
See the datasheet p. 94.

One more question, I installed the items that came on the CD, these were MPASMWIN and ProgPic2.exe, these work but arent very friendly and no IDE. I donwloaded and installed that Picprog2006 you mentioned but even in compatability mode it doesnt work with my programmer or PIC. I have downloaded the MPLAB IDE and am checking out the IDE by fiddling with the getting started guide. Should I not use the picprog2006 and just stick with the IDE and them compile using the former tools? Thanks again for the patience and help.

I hae managed to get that working with the include file, scrapped the template and used the demo that came with my programmer. Tell me, if i wanted to use my PIC to drive an L.E.D. matrix, how exactly would I change the assignment of inputs and outputs to reference the 10 outputs i require and 4 inputs?

I have this code file so far.

[code];**************************************************************************

list      p=16f627
#include <p16f627.inc>

__CONFIG        _BODEN_ON & _CP_OFF & _DATA_CP_OFF & _PWRTE_ON & _WDT_OFF & _LVP_OFF & _MCLRE_ON & _XT_OSC

;==========================================================================
; Variable Definition
;==========================================================================
;INPUTS
SW1 EQU H’00’ ;SW1 is triggering RA0
SW2 EQU H’01’ ;SW2 is triggering RA1
SW3 EQU H’02’ ;SW3 is triggering RA2
SW4 EQU H’03’ ;SW4 is triggering RA3
TIMER1 EQU H’20’ ;Used in delay routine
TIMER2 EQU H’21’ ; " " "
PATERN EQU H’22’ ;Pattern data for effect’s

	ORG	0		;Reset vector address
	GOTO	RESET		;goto RESET routine when boot.

; *********************************************
; * Delay routine *
; *********************************************

DELAY_ROUTINE MOVLW D’100’ ;54 Generate approx 10mS delay at 4Mhz CLK
MOVWF TIMER2
DEL_LOOP1 MOVLW D’100’ ;60
MOVWF TIMER1
DEL_LOOP2 BTFSC PORTA,SW1
GOTO MENU
BTFSC PORTA,SW2
GOTO MENU
BTFSC PORTA,SW3
GOTO MENU
BTFSC PORTA,SW4
GOTO MENU
DECFSZ TIMER1,F
GOTO DEL_LOOP2
DECFSZ TIMER2,F
GOTO DEL_LOOP1
RETLW 0

; **********************************
; ** RESET : main boot routine **
; **********************************

RESET MOVLW B’00000111’ ;Disable Comparator module’s
MOVWF CMCON
;
BSF STATUS,RP0 ;Switch to register bank 1
;Disable pull-ups
;INT on rising edge
;TMR0 to CLKOUT
;TMR0 Incr low2high trans.
;Prescaler assign to Timer0
;Prescaler rate is 1:256
MOVLW B’11010111’ ;Set PIC options (See datasheet).
MOVWF OPTION_REG ;Write the OPTION register.
;
CLRF INTCON ;Disable interrupts
MOVLW B’11000000’
MOVWF TRISB ;RB7 & RB6 are inputs.
;RB5…RB0 are outputs.
MOVLW B’11111111’ ;all RA ports are inputs
MOVWF TRISA
BCF STATUS,RP0 ;Switch Back to reg. Bank 0
CLRF PORTB
GOTO EFFECT_4
;

MENU CLRF PORTB
;
BTFSC PORTA,SW1
GOTO EFFECT_1
BTFSC PORTA,SW2
GOTO EFFECT_2
BTFSC PORTA,SW3
GOTO EFFECT_3
BTFSC PORTA,SW4
GOTO EFFECT_4
GOTO MENU

EFFECT_1 BTFSC PORTA,SW1
GOTO EFFECT_1
E1 ; effect 1 here
GOTO E1
EFFECT_2 BTFSC PORTA,SW2
GOTO EFFECT_2
E2 ; effect 2 here
GOTO E2
EFFECT_3 BTFSC PORTA,SW3
GOTO EFFECT_3
E3 ; effect 3 here
GOTO E3
EFFECT_4 BTFSC PORTA,SW4
GOTO EFFECT_4
E4 ; effect 4 here
GOTO E4

END[/code]

If I changed this so that it would output 4 effects to an L.E.D. matrix, of 5 x 5 i would need 10 outputs, what additional circuitry would I need with the PIC? Do I need an external oscillator or any other components or can I just power up the PIC and have it drive the L.E.D’s with no additional circuitry? (Other than the necessary resistors of course). Could someone also explain the whole “reset” of this thing to me? I tried copying eerything except the reset process into the template and it would not work.

Thanks

Part of learning assembler is actually learning assembler…

You can use the internal oscillator of the PIC. (_INTRC_OSC_NOCLKOUT to __CONFIG)

Then add your code to turn some I/O pins as outputs (use TRISx register). Then turn these outputs to 1 or 0 (use PORTx register). Connect a LED between the outputs with series resistor. You need only the resistors and LEDs for the LED array.

Connect pin 4 (RA5/MCLR/VPP) to VDD via a 2k2 resistor.

Hmm, it was a matrix i wanted to se up not an array, so you saying i can do this without the diodes? I assume you mean by switching outputs i want off so that the potential across that L.E.D. is 0. I was planning on buying a matrix of L.E.D’s anyway from maplin of 7 x 5. Thanks for the help. Much appreciated.

Sorry – I meant matrix.
Here is an example of a LED matrix:
vellemanprojects.com/be/en/p … ?id=343945
and the circuit diagram:
velleman.be/images/tmp/MK123.wmf
(If there are missing lines in this image then save it first and then double click the saved file. Windows Picture and Fax Viewer opens and shows it OK. Or drag it to MS Word document)

Ahh, exactly what i was thinking, this looks good. I’m not planning on making a clock so I probably don’t need the perfectly sync’d clock or the switches etc. I’ll have a look round for the sample code for this and play around with it … after i convince the university lab technician that giving me 35 hyperbright L.E.D’s would be benificial to him … oh dear am I in for a challenge. Thanks again, you have been most helpful.

Nice that you like it :slight_smile:
Take care and good luck!