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.

Anybody have PICC Lite example code?

Status
Not open for further replies.

futz

Active Member
I decided to try out PICC Lite (ships with MPLAB). Rather than figure out all the #include type stuff myself (I'm lazy) I thought I'd ask if anyone here can donate a simple, typical program for a 16F chip (I'm going to start with 16F877) that I could use as a quicky "skeleton" to get rolling with.

Anyone? :p

Since I started using C30 for the 30F chip, I've realized that I don't dislike C as much as I remembered. It's not so bad. So maybe I'll use it a bit more on other chips.
 
Last edited:
Hey futz,
There is a bit of confusion on PICC - You mean the CCS compiler for the 12 bit devices, which comes with MPLab? or the HiTech PIC compier? They both seem to want the PICC handle. If what you refer to is the former, you won't be able to write for the 16xx, only the 12xx chips.

There is some sample code for both, actually, here:
https://www.microchipc.com/

He also compares the two compilers mentioned above HiTech's is around 1200 per family, CCS is around 120 per family....
 
AtomSoft said:
I also have the CCS Compiler PCWH thanks for the link i had lost that one lol anymore out there?
Just google, something like:
" #FUSES NOWDT " or " #use delay(clock=4000000) " and you should get lots of hits.

Here is a very good one for CCS compilers:
https://www.phanderson.com/
 
Last edited:
BeeBop said:
There is a bit of confusion on PICC - You mean the CCS compiler for the 12 bit devices, which comes with MPLab? or the HiTech PIC compiler?
Definitely Hi-Tech PICC Lite v9.60. I've looked at a few of those examples and I'm still a bit lost.

How do I tell the compiler what chip I'm using? Do I just include pic.h and that's it?

How do I properly set config bits with PICC?

I haven't seen an example so far that does the above stuff.
 
futz said:
Definitely Hi-Tech PICC Lite v9.60. I've looked at a few of those examples and I'm still a bit lost.

How do I tell the compiler what chip I'm using? Do I just include pic.h and that's it?
Yep. It is a lot like the SourceBoost compiler here.
How do I properly set config bits with PICC?
__CONFIG(UNPROTECT|BODEN|FOSC1|BKBUG|WRT);


I haven't seen an example so far that does the above stuff.

Download Shane's RS232 Serial port from
https://www.microchipc.com/sourcecode/ for a good example.

I think HiTech builds a good compiler which is very close to ANSI C compliant, but there is some cost with getting up to speed on it (as well as its rather high monetary cost.) It will handle pointers to constants, which CCS is just beginning to address.
 
BeeBop said:
(as well as its rather high monetary cost.)
Just looked, and fell on the floor! $1000!!! That's insane! Guess I won't be buying that compiler anytime soon (ever). I'm a hobbiest, not a millionaire. :D

Same goes for C30. Burning a grand on a good compiler is not such a problem if you're a company building products. You just write it off as a business expense. But for hobbiests spending that kind of $$ is just not gonna happen.
 
From a hobby point of view the tool chain you can afford should be one of the main factors driving your chip choice.

For the 16F's I like the CCS compiler. They sell it for $250 but educators and maybe students can get it for $100 or $125. You only have 30 or 90 days of support and they lock you out of the downloads after that. Yeah I know, mind like a steel sieve.

The 18F's look better all the time.
 
futz said:
Just looked, and fell on the floor! $1000!!! That's insane! Guess I won't be buying that compiler anytime soon (ever). I'm a hobbiest, not a millionaire. :D

Same goes for C30. Burning a grand on a good compiler is not such a problem if you're a company building products. You just write it off as a business expense. But for hobbiests spending that kind of $$ is just not gonna happen.
:D :D :D

Well, if I was commercial, would probably consider it, but ... yea, he he...
However, I have been using SourceBoost C, which seems very close to HiTech's offering -
http://www.sourceboost.com/
and which cost less than a hundred, for a full license. (I think it was around 50 bux! on ebay...) It is a great little compiler...

I think C18 gives hobbyists a pretty good break...

I remember writing to Paul, the owner of _crossworks when I was working on the Phillips LPC mcu, and asking for an option for the serious hobbyist, and in fact he delivered, albeit, not by the time I needed it, but just the same, he did deliver. Now there is an excellent compiler, for the Phillips ARM, which is within reach!
 
OK, just one more stupid newbie question before I go off and write some code :D

I've written a blinky program for 877 that blinks LED on RB0.
Code:
#include <pic.h>
#include <htc.h>

__CONFIG(XT|WDTDIS|LVPDIS);

void delay(void);

int main(void)
{
	TRISB=0;
	while(1)
	{
		PORTB=0x01;
		delay();
		PORTB=0x00;
		delay();
	}
}

void delay(void)
{
	int x,y;
	for(x=0;x<10;x++)
	{
		for(y=0;y<10000;y++){}
	}
}
It compiles fine. I program the chip. It doesn't work. I look at the disassembly listing and see this:
Code:
---  C:\MCU\16f877\blinky_c\blinky.c  ------------------------------------------------------------
1:                 #include <pic.h>
2:                 #include <htc.h>
3:                 
4:                 __CONFIG(XT|WDTDIS|LVPDIS);
5:                 
6:                 void delay(void);
7:                 
8:                 int main(void)
9:                 {
10:                	TRISB=0;
  07D6    1683     BSF 0x3, 0x5
  07D7    1303     BCF 0x3, 0x6
  07D8    0186     CLRF 0x6
11:                	while(1)
  07DF    2FD9     GOTO 0x7d9
12:                	{
13:                		PORTB=0x01;
  07D9    3001     MOVLW 0x1
  07DA    1283     BCF 0x3, 0x5
  07DB    0086     MOVWF 0x6
14:                		delay();
  07DC    27E0     CALL 0x7e0
15:                		PORTB=0x00;
  07DD    0186     CLRF 0x6
16:                		delay();
  07DE    27E0     CALL 0x7e0
17:                	}
18:                }
19:                
20:                void delay(void)
21:                {
22:                	int x,y;
23:                	for(x=0;x<10;x++)
  07E0    0183     CLRF 0x3
  07E1    01A0     CLRF 0x20
  07E2    01A1     CLRF 0x21
  07F2    0AA0     INCF 0x20, F
24:                	{
25:                		for(y=0;y<10000;y++){}
  07E3    01A2     CLRF 0x22
Umm... Where's the rest? That just isn't going to work. :p

EDIT: Hmm... Maybe I should see if I need to switch pins to digital from analog... Nope, that doesn't help.
 
Last edited:
yes, I don't see it return from the delay....
and I'm running out of time... my GF is here from Kelowna, and in a couple of minutes, have to put all this away...
I'll try and look later if I can
 
Another example. Something is wrong. Source:
Code:
#include <pic.h>
#include <htc.h>

__CONFIG(XT|WDTDIS|LVPDIS);

int main(void)
{
	int x;
	ADCON1 = 6;
	TRISB = 0;
	while(1)
	{
		PORTB = 0x01;
		for(x=0;x<32767;x++){}
		PORTB = 0x00;
		for(x=0;x<32767;x++){}
	}
}
and the disassembly listing:
Code:
---  C:\MCU\16f877\blinky_c\blinky.c  ------------------------------------------------------------
1:                 #include <pic.h>
2:                 #include <htc.h>
3:                 
4:                 __CONFIG(XT|WDTDIS|LVPDIS);
5:                 
6:                 int main(void)
7:                 {
8:                 	int x;
9:                 	ADCON1 = 6;
  07E0    3006     MOVLW 0x6
  07E1    1683     BSF 0x3, 0x5
  07E2    1303     BCF 0x3, 0x6
  07E3    009F     MOVWF 0x1f
10:                	TRISB = 0;
  07E4    0186     CLRF 0x6
11:                	while(1)
12:                	{
13:                		PORTB = 0x01;
  07E5    3001     MOVLW 0x1
  07E6    1283     BCF 0x3, 0x5
  07E7    0086     MOVWF 0x6
14:                		for(x=0;x<32767;x++){}
  07E8    01A0     CLRF 0x20
  07E9    01A1     CLRF 0x21
  07EA    0AA0     INCF 0x20, F
  07EB    1903     BTFSC 0x3, 0x2
  07EC    0AA1     INCF 0x21, F
  07ED    0A20     INCF 0x20, W
  07EE    307F     MOVLW 0x7f
  07EF    1903     BTFSC 0x3, 0x2
  07F0    0621     XORWF 0x21, W
  07F1    1D03     BTFSS 0x3, 0x2
  07F2    2FEA     GOTO 0x7ea
15:                		PORTB = 0x00;
  07F3    0186     CLRF 0x6
16:                		for(x=0;x<32767;x++){}
  07F4    01A0     CLRF 0x20
Weird! I don't understand what's going on. It just stops in mid code.
 
What is the actual configuration word (hex value)? Are you sure that the WDT is disabled? I often use Hi-Tech PICC and the syantax of the __CONFIG() function looks different in your code. I usually AND the config labels.
 
eng1 said:
What is the actual configuration word (hex value)? Are you sure that the WDT is disabled? I often use Hi-Tech PICC and the syantax of the __CONFIG() function looks different in your code. I usually AND the config labels.
When I attempt to use the debugger, it complains that WDT is not disabled. I stole that config line format from another PICC programmer's code. It might not be right.

EDIT: That was it. Changed to
Code:
__CONFIG(XT&WDTDIS&LVPDIS);
and it works fine now.

The disassembly listing is still screwed, but as long as the compiler is actually working then I'm in business.

Thanks eng1 :D
 
Last edited:
Here's proof that it works! :D

**broken link removed**

And the code:
Code:
#include <pic.h>
#include <htc.h>

__CONFIG(XT&WDTDIS&LVPDIS);

void delay(void);

int main(void)
{
	char x;
	ADCON1 = 6;
	TRISB = 0;
	while(1)
	{
		PORTB = 0x01;
		delay();
		for(x=1;x<6;x++)
		{
			PORTB = PORTB << 1;
			delay();
		}
	}
}

void delay(void)
{
	int x,y;
	for(x=0;x<1;x++)
	{
		for(y=0;y<10000;y++){}
	}
}
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top