![]() | ![]() | ![]() |
| | #16 | |
| Quote:
| ||
| |
| | #17 |
| Only in that code written to use it requires your version of the modified pxxfxxxx.h file for your code to work. For the sake of sanity do not use the original file name! It would also cause the file to be a bit harder to read because the reader would have to look to the .h file to see the nonstandard name. Neither is a big deal, but I suggest it should be done with a good reason, not because you can. In some cases people have rewritten the entire naming convention for embedded compilers. One example is Peter Anderson custom header files that he uses with the CCS compiler. Most of the time we use #define to provide alternate names for ports and bits.
__________________ Please post questions to the forums. PM's are for personal communication. BCHS/3v0's Tutorials Junebug USB PIC programmer kit., USB Bit Whacker, The 15 Minute Printed Circuit Board! (+drill time) | |
| |
| | #18 |
|
I was just wondering what other trouble it might cause. I woulden't change it, like you said there aren't many good reasons to do that instead of just using define. Keeping things standard is hard enough with all the versions of any given language we already have.
| |
| |
| | #19 |
|
Can anyone point me to a good demo or tutorial of using the timers and/or capture compare in C18? I've been trying to find examples and tutorials, but most of the code I can find is not meant to be an example, so it's got a lot of other stuff and not commented with a newb in mind.
| |
| |
| | #20 | |
|
I don't think you'll find that with C18 Quote:
learn a lot like that. here a little http://w3.id.tue.nl/fileadmin/id/obj...utorial_EN.pdf Last edited by be80be; 26th June 2009 at 11:38 PM. | ||
| |
| | #21 |
|
Thanks for the tip. How different is Hitech C? Im finding a lot of stuff on that. Last edited by Triode; 27th June 2009 at 12:30 AM. | |
| |
| | #22 |
|
Theres a program structure that I often see in small game programming, and I wonder if it would work well with pics, and how it could be done. After all the setup and configuration a timer is started to call all the functions that need to repeat on a regularly timed interval. Since PICs are limited to only a few timers this would have to be modified to allow different frequencies of calling. I was thinking it could be done by having the timer call a function, withen it would be several entries like this, but for different frequencies of call: (pseudo code) called by timer, how often depends on whats a reasonable load Count1000ms += 1 (or instead of 1, whatever represents the number of ms per call) If Count1000ms >= 1000 then Call All 1000msFuntions Count1000ms = 0 end if same thing for all the other frequencies needed (end pseudo code) Im thinking this isnt a practical way to manage program timing on a PIC since no one seems to do it this way. But I cant see where the problem would be. I'll try it out when i figure out how to set up the timer. Last edited by Triode; 29th June 2009 at 09:32 PM. | |
| |
| | #23 |
|
Read Cooperative Multitasking on this page. There is also a zip with a MPLAB project with the code for use on a PIC18F1320 but it can easily be adapted to others. 3v0's Tutorials
__________________ Please post questions to the forums. PM's are for personal communication. BCHS/3v0's Tutorials Junebug USB PIC programmer kit., USB Bit Whacker, The 15 Minute Printed Circuit Board! (+drill time) | |
| |
| | #24 |
|
oh, heh, cant belive I missed that, I've been using your website. Thanks again.
| |
| |
| | #25 |
|
I'm trying to use the multitasking demo from your site, so far all I've done is created a project, pasted the code, and programmed it on to the chip. For those who aren't familiar with the program it is below. This is the one called DJ_coop2.c. When the junebug is started up, it lights the leftmost led and that's it, it stays on. I have tried it in debug and release mode under build configuration, and the switches on the junebug are all on except for 6. What part of this code starts the timer? is it part of multiCompiler.h? Code: /*
* Junebug Demo
* Purpose: Demonstrate cooporative multitasking
* using 1 Junebug LED + AC coupled speaker on RB1
*
* File: DJ_coop2.c
* Software: BoostC or Microchip C18 compilers
* Hardware: Junebug (or other debugger + breadboarded circuit)
*
* by Daniel Johnson
* July 2008
*/
#include "multiCompiler.h"
//
// defines & macros
//
#define TRUE !0
#define FALSE 0
#define byte unsigned char
#define uInt unsigned int
#define state case
#define KMAX 3
#define BLINK 0
#define BEEP 1
#define DUR 2
#define TASK_BLOCKED 0xFFFF
#define LED_BIT_HI porta_=0b00000001
#define LED_BIT_LO porta_=0b00000000
#define SPEAKER_BIT_HI portb_=0b00000010
#define SPEAKER_BIT_LO portb_=0b00000000
// allocate KMAX kTimers
uInt kTimer[KMAX];
byte waitForTimer;
void interrupt(void)
{
byte k;
// clear the IF
intcon_.TMR0IF = 0;
for (k=0;k<KMAX;k++)
{
// hold at 0
if((kTimer[k]) && // stop at zero
(kTimer[k]!=TASK_BLOCKED)) // task is blocked
{
kTimer[k]--;
}
}
waitForTimer = FALSE;
}
void taskBlink(void)
{
static byte seq=0;
switch (seq)
{
state 0:
LED_BIT_HI;
seq=1;
break;
state 1:
LED_BIT_LO;
seq=0;
}
// set when to run again
kTimer[BLINK]=1953;
return;
}
void taskBeep(void)
{
static byte seq=0;
switch (seq)
{
state 0: // state INIT
kTimer[DUR]=750;
seq=1;
break;
state 1: // state ON
SPEAKER_BIT_HI;
kTimer[BEEP]=2; // 1000 Hz
seq=2;
break;
state 2: // state OFF
SPEAKER_BIT_LO;;
if(kTimer[DUR]) // another pulse
{
kTimer[BEEP]=2;
seq=1;
}
else // generate a rest
{
kTimer[BEEP]=750;
seq=0;
}
}
}
//
// --- main ---
//
void main (void)
{
byte i;
// setup
{
// speed up the clock to 8MHz, 18F1320
osccon_.IRCF0=1;
osccon_.IRCF1=1;
osccon_.IRCF2=1;
// configure ports
adcon1_ = 0xFF; // all digital
// Switches on RB0 RB2 and RB5
//intcon2_.RBPU = 0; // PORTB weak pullups for switches
trisb_ = 0xFD; // speaker on RB1
lata_ = 0;
trisa_ = 0xBE; // RA0 and RA6 ouputs 0b1011 1110;
// configure Timer0
t0con_ = 0xD0;
intcon_.TMR0IF = 0; // clear the IF
intcon_.TMR0IE = 1; // enable TMR0 overflow interrupt
t0con__.TMR0ON = 1; // turn on TMR0
intcon_.GIE = 1; // enable global interrupts
// zero out the counters
for (i=0; i<KMAX;i++)
{
kTimer[i] = 0;
}
}
// kTimer[BEEP] = TASK_BLOCKED; // disable taskBeep
while(1) // main loop
{
if (!kTimer[BLINK])
{
taskBlink();
}
if (!kTimer[BEEP])
{
taskBeep();
}
while(waitForTimer);
waitForTimer = TRUE;
}
}
Code: /*
* Junebug Demo
* Purpose: Demonstrate cooporative multitasking
*
* File: multiCompiler.h
* Software: BoostC or Microchip C18 compilers
* Hardware: Junebug (or other debugger + breadboarded circuit)
*
* These defiles allow the use of more then one compiler.
* Register names ending with a single _ are byte referances.
* Register names ending with a dual __ are bit referances.
*
* by Daniel Johnson
* July 2008
*/
#ifdef _BOOSTC
#define FOUND_COMPILER
#define lata_ lata
#define trisa_ trisa
#define porta_ porta
#define latb_ latb
#define trisb_ trisb
#define portb_ portb
#define intcon_ intcon
#define intcon2_ intcon2
#define osccon_ osccon
#define t0con_ t0con
#define t0con__ t0con
#define adcon1_ adcon1
#include <system.h>
#pragma CLOCK_FREQ 8000000
#pragma DATA _CONFIG1H, _INTIO2_OSC_1H
#pragma DATA _CONFIG2H, _WDT_OFF_2H
#pragma DATA _CONFIG3H, _MCLRE_ON_3H
#pragma DATA _CONFIG4L, _LVP_OFF_4L
#endif
// MCC18
#ifdef __18CXX
#define FOUND_COMPILER
#define lata_ LATA
#define trisa_ TRISA
#define porta_ PORTA
#define latb_ LATB
#define trisb_ TRISB
#define portb_ PORTB
#define intcon_ INTCONbits
#define intcon2_ INTCON2bits
#define osccon_ OSCCONbits
#define t0con__ T0CONbits
#define t0con_ T0CON
#define adcon1_ ADCON1
#pragma config OSC = INTIO2, WDT = OFF, LVP = OFF
#include <p18f1320.h>
// code to make C18 interrupt look like BoostC's
void interrupt(void);
#pragma code low_vector=0x18
void low_interrupt (void)
{
_asm GOTO interrupt _endasm
}
#pragma code
#pragma interruptlow interrupt
#endif
#ifndef FOUND_COMPILER
error: unknown compiler
#endif
Last edited by Triode; 2nd July 2009 at 02:57 AM. | |
| |
| | #26 |
|
That code is for both C18 and BoostC so in your main code did you define which your using I may be wrong but in your main.C or what you called it should have #define __18CXX or the multicompiler.h wouldn't have ifdef _BOOSTC and ifdef __18CXX Ask 3v0 and see what he tells you i've never really done it with multicompiler but I have aways had to say hay I going to use A or B with a ifdef in a module Last edited by be80be; 2nd July 2009 at 04:12 AM. | |
| |
| | #27 |
|
save thing happen for me i built it and just the left led came on
| |
| |
| | #28 |
|
I run this program with switches 1-3 on as no others are required. Start with either the C18 or BoostC project. The program compiles as expected with the target chip set to 18F1320. You do not need to modify the code, This program runs two tasks at the same time. The first task blinks the LED nearest the USB connector. The second beeps a speaker connected as indicated in the tutorial. This demo requires a small speaker like that used in a PC. This bit of code Code: #define SPEAKER_BIT_HI portb_=0b00000010 #define SPEAKER_BIT_LO portb_=0b00000000 gnd -----(speaker)----)|--------- RB1 RB1 is on the connector next to the USB. I tried both C18 and BoostC. In both cases the LED blinked while the code was running. The timer is configured in main by the code following Code: // configure Timer0 Give it another try and if it does not blink the LED I can talk about what might be wrong. 3v0
__________________ Please post questions to the forums. PM's are for personal communication. BCHS/3v0's Tutorials Junebug USB PIC programmer kit., USB Bit Whacker, The 15 Minute Printed Circuit Board! (+drill time) | |
| |
| | #29 |
|
Like i said I wasn't sure you had to set what compiler it builds fine but I don't think it set the chip. I no I loaded it with mplab and i got the one led on. What i did was open the pickit2 and load it with it and it said this hex doesn't have config bits set right for your chip take a look and see if this tells you any thing
Last edited by be80be; 2nd July 2009 at 01:26 PM. | |
| |
| | #30 |
|
Thanks for all the help. My student version of MPLAB keeps locking up, even before I open a project, so I'm going to reinstall it. Who knows, that may fix the problem I'm having with the junebug too. Once I get home and get time to work on this, and apply your advice if the reinstal doesnt fix it, I'll let you know how it goes.
| |
| |
|
| Tags |
| c18, questions |
| Thread Tools | |
| Display Modes | |
| |
Similar | ||||
| Title | Starter | Forum | Replies | Latest |
| A few questions | erosennin | Feedback/Comments | 24 | 29th November 2007 12:08 AM |
| 2 questions | juan123 | Electronic Projects Design/Ideas/Reviews | 5 | 27th September 2007 03:46 AM |
| A few questions. | Marks256 | General Electronics Chat | 55 | 5th August 2006 11:49 PM |
| few questions | Victor Frankenstein | General Electronics Chat | 13 | 5th July 2005 07:29 PM |
| Questions? | Philipc | Electronic Projects Design/Ideas/Reviews | 4 | 7th August 2003 07:18 PM |