I have programmed many different C programs for PIC16F876 and PIC16F84A, and I have built 3 different prototypes for writing a simple string on an LCD display using HD44780 controller. All of them worked when simulated in ISIS, none worked when programmed on the real PIC.
I now want to test if I'm doing something wrong or if it's the programmer/PIC that's not working. To do so I'd like to use PIC16F84A with a simple binary 8-bit counter on PORTB connected to LEDs. But my programs are not working at all on the real PIC. Could someone please write a simple C program and give me C source, HEX and schematic for it?
Thank you in advance
#define _XTAL_FREQ 4000000
#include <htc.h>
/* XTAL Oscillator
* Watchdog timer OFF
* Power up timer OFF
* Code protection OFF
*/
__CONFIG(FOSC_XT & WDTE_OFF & PWRTE_OFF & CP_OFF);
char MyCounter;
void main(void){
// Intializing ports as outputs, and port value 0
TRISA=0x00;
TRISB=0x00;
PORTA=0x00;
PORTB=0x00;
// Counting on PORTB, forever
while (1){
//output the counter on the port pins
PORTB = MyCounter++;
// I'll give it 250ms delay so I can
// watch changes on the output LEDs
__delay_ms(250);
}
}
Every approach has its limitations. I have completed many code projects, otherwise imposible debugging for me, only using simulators. But if you have very basic fault in your hardware, simulators can't be blamed.Pretty symptomatic for simulators
#define _XTAL_FREQ 4000000
#include <htc.h>
// The LCD driver
#include "HD44780.h"
#include "HD44780.c"
/* XTAL Oscillator
* Watchdog timer OFF
* Power up timer OFF
* Code protection OFF
*/
__CONFIG(FOSC_XT & WDTE_OFF & PWRTE_OFF & CP_OFF);
void main(void){
// Intializing ports as outputs, and port value 0
TRISA=0x00;
TRISB=0x00;
PORTA=0x00;
PORTB=0x00;
// Initializing LCD
LCD_Initialize();
// Writing the string as follows (\n will jump to line 2)
// 0123456789ABCDEF
// FEDCBA9876543210
LCD_WriteString("0123456789ABCDEF\nFEDCBA9876543210");
}
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?