0% found this document useful (0 votes)
154 views

PIC18F26K22 Serial Hello World Example

The document summarizes the author's experience getting serial output working on a PIC18F26K22 microcontroller. After having issues with another chip, the author switched to the PIC18F26K22 due to its useful interfaces. While examples existed, none worked for the author initially. Through additional troubleshooting, the author developed a simple "Hello World" example program using serial output on the chip. The example is provided to help others save time in getting serial working on the PIC18F26K22.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
154 views

PIC18F26K22 Serial Hello World Example

The document summarizes the author's experience getting serial output working on a PIC18F26K22 microcontroller. After having issues with another chip, the author switched to the PIC18F26K22 due to its useful interfaces. While examples existed, none worked for the author initially. Through additional troubleshooting, the author developed a simple "Hello World" example program using serial output on the chip. The example is provided to help others save time in getting serial working on the PIC18F26K22.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

PIC18F26K22 World example

Filed under: projects Leave a comment

Serial

Hello

April 1, 2013

After having compiler issues using the new PIC18F25K50 chip, I switched to the K22 series. Specifically the 28 pin PIC18F26K22. The dual USART, dual SPI/I2C interfaces will be handy and allow for more flexible board layouts. But, I had some difficulty getting the serial output to work. I read through a variety of examples, and questions/problems posted by others, most without responses. I did find several examples, but none of these worked. With some additional messing about, I managed to come up with this minimal Hello World example. Hopefully the following will save someone else some time.
/* Serial Hello World * This works! * Clock set to 4Mhz, no PLL, transmits at 2400 Baud * PIC18F26K22 * Complier: C18 v 3.45 */
#include #include #include #include #include #include #pragma config FOSC = INTIO7 // internal clock, clock output on RA6 /* IRCF: Internal RC Oscillator Frequency Select bits(2) 111 = HFINTOSC (16 MHz) 110 = HFINTOSC/2 (8 MHz) 101 = HFINTOSC/4 (4 MHz) 100 = HFINTOSC/8 (2 MHz) 011 = HFINTOSC/16 (1 MHz) */ void main (void) {

OSCCONbits.IRCF = 0b101; //change Fosc to 4Mhz // wait until IOFS = 1 (osc. stable) while (!OSCCONbits.IOFS) /* * Open the USART configured as * 8N1, 2400 baud, in polled mode */ Open1USART (USART_TX_INT_OFF & USART_RX_INT_OFF & USART_ASYNCH_MODE & USART_EIGHT_BIT & USART_CONT_RX & USART_BRGH_HIGH, 103); while (1) { putrs1USART(Hello World!\n\r); Delay1KTCYx(1); } }
About these ads

Font: http://corgitronics.com/2013/04/01/pic18f26k22-serial-hello-world-example/

You might also like