Pic uController Problem: reading input

Thread Starter

PRS

Joined Aug 24, 2008
989
I'm just learning how to program using PicKit3 and Microchip's C18. I'm trying to read a byte of data on the C port of a PIC18f45k20, but I'm not getting the byte I'm inputting to the port. Can someone tell me what I'm doing wrong? Here's my code: (I used number2 just to set a break-point; it has no useful function).


/** C O N F I G U R A T I O N B I T S ******************************/

#pragma config FOSC = INTIO67, FCMEN = OFF, IESO = OFF // CONFIG1H
#pragma config PWRT = OFF, BOREN = SBORDIS, BORV = 30 // CONFIG2L
#pragma config WDTEN = OFF, WDTPS = 32768 // CONFIG2H
#pragma config MCLRE = OFF, LPT1OSC = OFF, PBADEN = ON, CCP2MX = PORTC // CONFIG3H
#pragma config STVREN = ON, LVP = OFF, XINST = OFF // CONFIG4L
#pragma config CP0 = OFF, CP1 = OFF, CP2 = OFF, CP3 = OFF // CONFIG5L
#pragma config CPB = OFF, CPD = OFF // CONFIG5H
#pragma config WRT0 = OFF, WRT1 = OFF, WRT2 = OFF, WRT3 = OFF // CONFIG6L
#pragma config WRTB = OFF, WRTC = OFF, WRTD = OFF // CONFIG6H
#pragma config EBTR0 = OFF, EBTR1 = OFF, EBTR2 = OFF, EBTR3 = OFF // CONFIG7L
#pragma config EBTRB = OFF // CONFIG7H


/** I N C L U D E S **************************************************/
#include "p18f46k20.h"
// include files go here....

/** V A R I A B L E S *************************************************/
#pragma udata // declare statically allocated uninitialized variables
unsigned char number, number2;

/** D E C L A R A T I O N S *******************************************/

#pragma code // declare executable instructions
void main (void)
{
TRISC = 0B11111111; // Port C is input
number = 0;
number = LATC;
number2 = 3;

while (1)
;
}
 

Thread Starter

PRS

Joined Aug 24, 2008
989
You're right, Mark. Thank you very much! I got up this morning and, after reading your post, changed LATC to PORTC and experimentally proved it was reading the input correctly. I can now read and write data to a breadboard! My goal is to make an EEPROM programmer. The next step is to configure a single port with various inputs and outputs. Thanks again! :)
 
Top