Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Pic microcontroller

Status
Not open for further replies.

TheKnight

Member
What is the best way to learn pic microcontrollers? I've got responses to get some eBooks but were not suitable. I have small experience with C++/C language and have compilers needed. I need a resource where i can learn with examples, well explained for beginners and entertaining. I am very interested in pic microcontrollers but can't seem to start. Seen a lot of beautiful projects and hope someone will respond. Help is very appreciated.
 
I already have MikroC Pro compiler

Then just buy, or copy the MicroC hardware, and go through the many example programs provided.

Mikro even sell books, I believe. Have not tried any for myself.

I can't think of anything I can suggest that is easier to learn than MikroC. It comes with very good help, accessed from the IDE.
Mikro also provide much sample code and some tutorial code.
 
Last edited:
I have the "Pic Microcontrollers - Programming in C" book from mikroElektronika, but most in the book is about the parts, not many examples, as much as I've seen. Do you think it's worth reading?
 
Do you think it's worth reading?
Cannot help you there. I have not read any Mikro books.

I prefer to learn by doing. Start really simple (flash LED), work my way up. See how others write their code.

If you are serious about MikroC as your learning route, you really need to move to the MikroElectronica forum; not this one. (apologies to the forum members here)
 
Quite honestly, when you're first starting out it's best to learn PIC assembly first. The syntax is much easier and you learn more about the hardware whereas in C a lot of the normal "housekeeping" is all done by the compiler. Plus you can right tighter code with PIC ASM IMHO.
 
What do you mean by Assembly?

As in the PIC assembly language. If you look toward the back of a PIC data sheet it will have the "Instruction Set Summary", with all of the assembly language instructions for the chip.

Here is an example of what PIC assembly source code would look like for flashing an LED on pin RA0 of a PIC16F628 -

Code:
;*************************************************************************************************
;**				Header Information						**
;*************************************************************************************************	
	
		list		p=16F628A, r=dec, w=-302
		include		<P16F628A.INC>
		__config	b'11110100100001'

;Processor is 16F628A (p)
;Radix is decimal unless otherwise noted (r)
;Errorlevel set to suppress bank select assembler messages (w)

;config word
;  ___   ___   ___   ___         ___                          _____
;| CP1 | CP0 | CP1 | CP0 |  -  | CPD | LVP |BODEN|MCLRE|FOSC2|PWRTE|WDTE |FOSC1|FOSC0|
;|  1  |  1  |  1  |  1  |  0  |  1  |  0  |  0  |  1  |  0  |  0  |  0  |  0  |  1  |

;Code Protection disabled (CP1-CP0)
;Data Code Protection disabled (CPD)
;Low Voltage Programming disabled (LVP)
;Brown Out Detection disabled (BODEN)
;RA5 is External Master Clear (MCLRE)
;Power Up Timer enabled (PWRTE)
;Watchdog Timer disabled (WDTE)
;Standard XT Oscillator (FOSC2-FOSC0)

;External frequency = 4MHz

;*************************************************************************************************
;**				RAM Location Labels						**
;*************************************************************************************************

COUNT1		EQU		0x20
COUNT2		EQU		0x21

;*************************************************************************************************
;**				Port Configuration						**
;*************************************************************************************************

		org		0x00		;reset vector
		goto		START		

START		bsf		INTCON,GIE	;disable interrupts
		movlw		b'00000111'	;disable on chip comparator
		movwf		CMCON		;RA0-RA4 are digital I/O
		banksel		TRISA		;bank 1
		movlw		b'00000000'	;RA0-RA4 outputs
		movwf		TRISA
		movlw		b'00000000'	;RB0-RB7 outputs
		movwf		TRISB
		banksel		RCSTA		;bank 0
		bcf		RCSTA,SPEN	;disable serial USART

;*************************************************************************************************
;**				Program Start							**
;*************************************************************************************************	

MAIN		bsf		PORTA,0		;turn on LED on pin RA0
		call		DELAY		;wait
		bcf		PORTA,0		;turn off LED on pin RA0
		call		DELAY		;wait
		goto		MAIN		;loop back and do it again forever

;*************************************************************************************************
;**				Subroutines							**
;*************************************************************************************************

DELAY		movlw		0xFF		;load count 1 and count 2 with maximum value
		movwf		COUNT1		;of 0xFF (decimal 255)
		movwf		COUNT2
		decfsz		COUNT1,F	;decriment register COUNT1 by a factor of 1
		goto		$-1		;loop back 1 line, skip when COUNT1=0
		decfsz		COUNT2,F	;decriment register COUNT2 by a factor of 1
		goto		$-3		;loop back 3 lines, skip when COUNT2=0
		return				;return from subroutine

		end

Anything with a semicolon in front of it is commented out (the equivalent of "//" in C).
 
Last edited:
Yeah, I have to disagree with learning assembly language first. It's very detailed. The first programming languages taught to kids isn't assembly, it's high-level languages like BASIC, Logo and such. Once you understand programming then you can dive into the nitty-gritty of assembly.
 
Which is interesting because the only language I even know is assembly. I never could figure out the higher level languages yet assembly only took me a few times of reading a certain tutorial before I had a decent grasp on it.
 
I have programmed with assembly, c and basic on the PIC. To be quite honest, especially on Pic's, who can be bothered these days setting up bank selects working out what memory is where!!! Its tons easier to program in C and let the compiler deal with these mundane tasks. Don't you think? When assembly is called for just include it in C.

Cheers Ian
 
I have programmed with assembly, c and basic on the PIC. To be quite honest, especially on Pic's, who can be bothered these days setting up bank selects working out what memory is where!!! Its tons easier to program in C and let the compiler deal with these mundane tasks. Don't you think? When assembly is called for just include it in C.

If you already have a decent understanding of the PIC, either in assembler, or just the hardware itself, then there's no problem using C at all - if you like C :D

But the problem comes with people starting on the PIC (or other processors) just in C, they don't have a clue about the hardware and what's required, and as most application notes are in assembler it means they struggle finding how to do things.

Historically programmers at University weren't allowed to use HLL's until they had a sound grounding in assembler, and I think that is really as important now as it was then.
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top