Step 4Setting Up Our Microcontroller!
Note: My hello world program sends "Hello World!\r\n" over Serial to my computer at 38400bps
#include <p18f2550.h> // Include file specific for this chip
#include <usart.h> // USART Functions
#include <stdio.h> // printf(format,...) , sprintf(string, format, ...), etc...
#include "delay.h"
void main(){
PORTA = 0x00;
PORTB = 0x00;
PORTC = 0x00;
TRISA = 0x00;
TRISB = 0x00;
TRISC = 0x00;
ADCON1 = 0x0F; // This is such a trouble maker, never forget to turn the Analogue pins back to digital! :P
TRISCbits.TRISC7 = 1; // Turns the RX pin into an input (look it up in your datasheet for your chip)
OpenUSART(USART_TX_INT_OFF & USART_RX_INT_OFF & USART_ADDEN_OFF & USART_BRGH_HIGH & USART_CONT_RX & USART_EIGHT_BIT & USART_ASYNCH_MODE,78);
while(1){
putrsUSART("Hello World!\r\n"); // Send a message via Serial
LATAbits.LATA0 = ~LATAbits.LATA0; //Flash an LED by toggling it on and off
DelayMS(500); // A delay function I've created
}
}
This was set up with a 3.3V power supply because the ink cartridges run on 3.3Volts
Why a hello world program? Well, every time I set up a new project on a bread board, I always want to make sure I've got the configureation bits correct and that I'm not getting garbage in the terminal.
I think this is good practice and everyone should do it! :P
If your chip is doing something simple like mine, Great!! on to the next step
| « Previous Step | Download PDFView All Steps | Next Step » |
1
comment
|
Add Comment
|
![]() |
Add Comment
|













































