pic18

What is the best c complier for the Pic18 micro

We are starting a new project based a microchip PIC18F252. What is the best 'c' compiler to use? ...

Produce tones at certain time-interval using C programming

Im using C language for a PIC18F to produce tones such that each of them plays at certain time-interval. I used PWM to produce a tone. But I don't know how to create the intervals. Here is my attempt. #pragma code // void main (void) { int i=0; // set internal oscillator to 1MHz //OSCCON = 0b10110110; ...

Keeping time using timer interrupts an embedded microcontroller

Hello, This question is about programming small microcontrollers without an OS. In particular, I'm interested in PICs at the moment, but the question is general. I've seen several times the following pattern for keeping time: Timer interrupt code (say the timer fires every second): ... if (sec_counter > 0) sec_counter--; ... Main...

Multithreading using C on PIC18

How does one create threads that run in parallel while programming PIC18, since there is no OS? ...

One Wire Problem

Hi all! I need your qualified help! I'm programing in C++, using a PIC 18F87J50 and trying to connect DS18B20 at my H0 Port! I think my underlying programing is correct so.... the problem I have (think I have), is when performing a ROM Command, I'm searching for the 64-bit ROM CODE. The first byte should tell me what family the compon...

1wire problem in detail

I have defined these functions below, and when I ask Device_ID function for example of the family code, I only get FF (should be 28), acctually I get both the family code, 48-bit serial, and the crc 8 bit to be all "ones". It seems like the detect slave device function works as it should.... If i connect the slave he say's I am here, and...

Delay in MCC18, 48Mhz, 18F87J50

How should i write a delay macro for an PIC 18f87J50 with a 48MHz crystal and compiler of MCC18. The delay should be in us. So I for example can write: Delay_us(201) and really get 201us delay. What I have now is: #define Delay_us(n) (Delay10TCYx(((n) * (uint16_t) 12 + 9) / 10)) And it does'nt seems right at my oscilloscope! :/ Kind...

Difference between PORT and LATCH on PIC 18F

I already read the datasheet and google but I still don't understand something. In my case, I set PIN RC6 of a PIC18F26K20 in INPUT mode: TRISCbits.TRISC6 = 1; Then I read the value with PORT and LATCH and I have different value! v1 = LATCbits.LATC6; v2 = PORTCbits.RC6; v1 gives me 0 where v2 gives 1. Is it normal? In ...

Create big buffer on a pic18f with microchip c18 compiler

Using Microchip C18 compiler with a pic18f, I want to create a "big" buffer of 3000 bytes in the program data space. If i put this in the main() (on stack): char tab[127]; I have this error: Error [1300] stack frame too large If I put it in global, I have this error: Error - section '.udata_main.o' can not fit the section. Sectio...

PIC Assembly function calling

I'm writing a pretty basic program in PIC18 assembly. It requires that I write a subroutine to multiply two 16-bit numbers... This is what I have right now: ;*********************************************************************** ; mul_16bit: subroutine that multiplies two 16 bit numbers stored in ; addresses mul_16ptr1, mul_16ptr1+1...

Best practice for function to handle 1-256 bytes

I have some functions that are designed to handle 1-256 bytes, running on an embedded C platform where passing a byte is much faster and more compact than passing an int (one instruction versus three), what is the preferred way of coding it: Accept an int, early-exit if zero, and otherwise copy the LSB of the count value to an unsigned...

How are divisions handled in the PIC18 ISA

Kind of an extension of http://stackoverflow.com/questions/3694100/converting-to-ascii-in-c , I was wondering exactly how divisions are handled on a PIC18X. If I perform a DIV operation, how many instructions does the compiler interpret that as? How many clock cycles will it take for the operation to complete? Is the number of clock cyc...

USART transmit problems on a PIC

I'm trying to send data to an SD card from a PIC18f4580, but the PIC is not sending what it should be. related global variables: unsigned char TXBuffer[128]; //tx buffer unsigned char TXCurrentPos = 0x00; //tracks the next byte to be sent unsigned char TXEndPos = 0x00; //tracks where new data should be put into the array I am adding ...

Why doesn't this compile in C18?

I'm trying to compile the following code using the MPLAB C18 v3.36 compiler. Compiler returns a syntax error on 'char rij;'. But when i put char rij; a line earlier (before TRISA = ...), it compiles ... void setup(void) { TRISD = 0b00000000; TRISA = 0b00000000; char rij; for (rij = 0; rij<ROWS; rij++) { red_byte_array[rij]=0; g...

Netmf SPI master to Pic18f4550 slave synchronization problem (C18)

A .NET Micro Framework device (ChipworkX in this case) sends a byte through the SPI interface to a Pic18f. Having PIE1bits.SSPIE enabled the following code is executed on interrrupt: void high_isr (void) { PIE1bits.SSPIE = 0; PIR1bits.SSPIF = 0;// Clear interrupt flag LATDbits.LATD5=1;//enables led for high interr...