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.

Help Converting PIC Assembly Language to BoostC

Status
Not open for further replies.

Mike - K8LH

Well-Known Member
Help Converting PIC Assembly Language Program to BoostC

Greetings Guys,

Just wondering if anyone would care to pass along any advice for converting this assembly language program to BoostC? It's a simple LED sequencer program that uses pointers to advance through the effects tables (constant arrays) but I'm still a little fuzzy about pointers in C.

I plan to work through this during the weekend but thought I'd post it here before heading off to classes this morning for anyone who had time to take a peek.

TIA.

Cheerful regards, Mike
 
Last edited:
I'll do it tonight for you... small enough program.... I will only have boostC lite but it should be okay..

Or are you wanting to do it yourself? I could put plenty of comments in.
 
Last edited:
I don't do C, but I'd 'point out' (pun intended) that pointers in assembler and pointers in C are VERY different things. There's probably no need to use C pointers, just arrays.
 
Thanks for comments and offers, Gentlemen.

I think I know how to set-up constant arrays in BoostC for each "effect" and I suspect I can figure out a way to make a constant "directory" array of pointers to the "effect" arrays. One thing I was wondering about is if there's a "sizeof" facility in the compiler that will return the size of the array (hopefully calculated at compile time) that I can use for calculating the number of sequence "steps" in each "effect" array. I'd like to make the "effect" arrays as intuitive as possible so that they can be edited easily by the user (modify, insert, or delete elements).

Ian, you don't have to post a complete program. If you want to convey some neat concept, I'm sure a code snippet and simple explanation would do nicely. On the other hand, if you or anyone else would like to post their C program solution for this simple sequencer program, I'm sure we would all benefit from studying the diversity of programming styles.

Kind regards, Mike
 
Last edited:
Mike....Here is my interpretation... Its in HI-TECH not boost sorry

Code:
#include <pic.h>				// pic specific identifiers
#define _XTAL_FREQ  4000000		// Xtal speed
__CONFIG(0x3D18);				// Config bits

#define LEDPORT PORTB
#define LEDTRIS	TRISB
#define SWTRIS	TRISA
#define SWPORT	PORTA
#define	SW1		RA0				// Pre- defined in pic.h

unsigned char TABLE1[20] ={		// 10 components 
		0b10000000, 10,
		0b11000000, 10,
		0b01100000, 10,
		0b00110000, 10,
		0b00011000, 10,
		0b00001100, 10,
		0b00000110, 10,
		0b00000011, 10,
		0b00000001, 10,
		0b00000000, 20};

unsigned char TABLE2[32] ={		// 16 components
		0b00000001, 10,
		0b00000010, 10,
		0b00000100, 10,
		0b00001000, 10,
		0b00010000, 10,
		0b00100000, 10,
		0b01000000, 10,
		0b10000000, 10,
		0b01000000, 10,
		0b00100000, 10,
		0b00010000, 10,
		0b00001000, 10,
		0b00000100, 10,
		0b00000010, 10,
		0b00000001, 10,
		0b00000000, 10};

unsigned char TABLE3[4] ={		// 2 components
		0b00001111, 20,
		0b11110000, 20};

unsigned char TABLE4[4] ={		// 2 components
		0b00000001, 25,
		0b00000010, 25};

unsigned char TABLE5[20] ={		// 10 components
		0b00000001, 10,
		0b00000011, 10,
		0b00000110, 10,
		0b00001100, 10,
		0b00011000, 10,
		0b00110000, 10,
		0b01100000, 10,
		0b11000000, 10,
		0b10000000, 10,
		0b00000000, 20};

void Delay(int speed);

void main(void)					// program entry
	{
	char index;
	char mode = 0;				// table to use
	char size = 0;				// new loop variable
	unsigned char *tblptr;
	CMCON = 0x7;				// Comparitors off
	SWTRIS = 0b11111111;		// Switch port as inputs LED's as outpts
	LEDTRIS = 0b00000000;
	tblptr = TABLE1;
	size = sizeof(TABLE1);
	while(1)					// Loop forever
		{
		for(index = 0; index < size  ; index+=2)
			{
			if(!RA0)
				{
				Delay(20);
				while(!RA0);
				if(++mode == 5) mode = 0;
				index = 0;
				switch(mode)
					{
					case 0:
						tblptr = TABLE1;
						size = sizeof(TABLE1);
						break;
					case 1:
						tblptr = TABLE2;
						size = sizeof(TABLE2);
						break;
					case 2:
						tblptr = TABLE3;
						size = sizeof(TABLE3);
						break;
					case 3:
						tblptr = TABLE4;
						size = sizeof(TABLE4);
						break;
					case 4:
						tblptr = TABLE5;
						size = sizeof(TABLE5);
						break;
					}
				}
			PORTB = tblptr[index];
			Delay(tblptr[index+1] * 10);
			}	
		}
	}

void Delay(int speed)					// required to simulate Nigels tutorial
	{
	while(speed--)
		{
		__delay_ms(1);		// Every 1 ms
		}		
	} 

// End!!
 
Last edited:
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top