The PIC18 series 8 bit microcontrollers manufactured by Microchip Technology.
Questions tagged [pic18]
230 questions
29
votes
8 answers
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 =…

acemtp
- 2,971
- 6
- 34
- 43
12
votes
5 answers
In Microchip C18, why does the insertion of a NOP cause much larger code?
I have some code in an ISR. The code is given for completeness, the question is only about the commented-out __asm_ block.
Without the __asm_ block, this is compiled into 82 instructions. With the __asm_ block, the result is 107 instructions long.…

AndreKR
- 32,613
- 18
- 106
- 168
9
votes
3 answers
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…

supercat
- 77,689
- 9
- 166
- 211
8
votes
13 answers
Multithreading using C on PIC18
How does one create threads that run in parallel while programming PIC18, since there is no OS?

M3.
- 81
- 1
- 2
6
votes
1 answer
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…

acemtp
- 2,971
- 6
- 34
- 43
5
votes
3 answers
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:…

Sean
- 3,002
- 1
- 26
- 32
5
votes
3 answers
Embedded code development (especially for PIC with C18) in Visual Studio
I'm using Visual Studio for writing desktop applications, and I find it very user friendly and easy to use.
If possible, I also want to write embedded code in Visual Studio. For example, is it possible to generate .hex files for PIC18Fxxx series…
user1399721
4
votes
11 answers
Keeping time using timer interrupts an embedded microcontroller
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…

Eli Bendersky
- 263,248
- 89
- 350
- 412
4
votes
2 answers
One Wire Problem
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…

Christian
- 1,548
- 2
- 15
- 26
3
votes
1 answer
Can "swap nybble" and "byte mask" tricks do multi byte logical shift by 4 much faster than the naive method of using bit shift chains
I'm writing a fixed-point (16Q16) algo that does division using the Newton–Raphson method outlined on Wikipedia. (Related SE question HERE.)
The first step requires logical right-shift by anywhere from 1-16 bits. My CPU is an 8-bit microcontroller,…

Charlie
- 258
- 2
- 9
3
votes
1 answer
Assembly instruction to machine code
I'm trying to convert MOVFF 0x10, 0x15 to machine code. The Microcontroller is Microchip PIC 18F1220. The reference manual says:
MOVFF fs,fd
Encoding:
1st word: 1100 ffff ffff ffffs
2nd word: 1111 ffff ffff ffffd
The solution is:
1100 0000 0010…

user
- 31
- 2
3
votes
3 answers
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 …
twiart
3
votes
1 answer
PIC 18F45K42: How to combine 4 bytes to Int?
I am writing code for a PIC 18F45K42 to read .wav files from an HCSD card. I am using MPLAB X IDE v5.20 and XC v2.05. I am using FATFs library to read data off the card.
I can read data off the card and get good results until it comes to combining…

Peter Wiley
- 820
- 7
- 19
3
votes
3 answers
Write UART on PIC18
I need help with the uart communication I am trying to implement on my Proteus simulation. I use a PIC18f4520 and I want to display on the virtual terminal the values that have been calculated by the microcontroller.
Here a snap of my design on…

Daymov
- 45
- 9
3
votes
1 answer
PIC18F25K80 sending string through USART not working
I'm programming a few libraries for a board with a PIC18F25K80 built-in. Right now I'm trying to program the UART library and I've tried everything but I cannot make it work when it comes to send a string of chars.
I'm using the XC8 compiler and I…