dvlee
Newbie level 3
Hi,
Im trying to get a PIC18F458 dev board to say something, anything! I started first with a VFD and now have scaled back to a simple LED program.
Have 2 source codes. Can someone point out where the encoding is at fault and what it should be?
Appreciate.
LED:
//05-03-12 LED TOGGLE
#pragma code InterruptVectorHigh = 0x2008
#pragma code InterruptVectorLow = 0x2018
#pragma code main = 0x2020
#include "H:\PROGRAMS AND MCU'S\PIC\PIC 18 2376 PROJECT\header files\p18f458.h"
#include "H:\PROGRAMS AND MCU'S\PIC\PIC 18 2376 PROJECT\header files\delays.h"
#include "H:\PROGRAMS AND MCU'S\PIC\PIC 18 2376 PROJECT\header files\lcd.h"
#include "H:\PROGRAMS AND MCU'S\PIC\Microchip\mplabc18\v3.41\h\xlcd.h"
#define key PORTDbits.RD1 /* PORT for key */
#define TRIS_key TRISDbits.TRISD1 /* TRIS for key */
void delay (void)
{
Delay10KTCYx(100);
}
void toggle(void)
{
if(LATB == 0xff)
LATB = 0;
else
LATB = 0xFF;
while(key) delay();
}
void main (void)
{
/* Make all bits on the Port B (LEDs) output bits.
/* If bit is cleared, then the bit is an output bit.
*/
TRISB = 0;
TRIS_key =1;
while (1)
{
if(key == 1) toggle();
}
}
VFD:
// 3.5-LCD-VFD 04-thur12-12.
// The following program requires the pic18f458 MCU to send to a noritake
// Vacuum Fluorescent Display (model: CU20045-UW5A)the basic "Hello World" character
// string.
#pragma config OSC = HS, OSCS = ON
#pragma config BORV = 45, PWRT = ON, BOR = ON
#pragma config WDT = ON
#pragma config DEBUG = ON, LVP = ON, STVR = ON
#include<p18f458.h>
#define LCD_data PORTD
#define LCD_rs PORTBbits.RB0
#define LCD_rw PORTBbits.RB1
#define LCD_en PORTBbits.RB2
#define LCD_D7 PORTDbits.RD7
void ms40();
void LCD_busy();
void LCD_init();
void LCD_senddata(unsigned char var);
void LCD_command(unsigned char var);
void LCD_sendstring(unsigned char var);
void ms40()
{
int i;
for(i=0;i<9000;i++);
}
void LCD_busy()
{
TRISDbits.TRISD7 = 1; // Configure port pin D7 for input
LCD_D7 = 1; //Make D7th bit of LCD as i/p
LCD_en = 1; //Make port pin as o/p
LCD_rs = 0; //Selected command register
LCD_rw = 1; //We are reading
while(LCD_D7) //read busy flag again and again till it becomes 0
{
LCD_en = 0; //Enable H->L
LCD_en = 1;
}
TRISDbits.TRISD7 = 0; // Configure port pin D7 for output
}
void LCD_init()
{
LCD_data = 0x38; //Function set: 2 Line, 8-bit, 5x7 dots
LCD_rs = 0; //Selected command register
LCD_rw = 0; //We are writing in data register
LCD_en = 1; //Enable H->L
LCD_en = 0;
LCD_busy(); //Wait for LCD to process the command
LCD_data = 0x0F; //Display on, Curson blinking command
LCD_rs = 0; //Selected command register
LCD_rw = 0; //We are writing in data register
LCD_en = 1; //Enable H->L
LCD_en = 0;
LCD_busy(); //Wait for LCD to process the command
LCD_data = 0x01; //Clear LCD
LCD_rs = 0; //Selected command register
LCD_rw = 0; //We are writing in data register
LCD_en = 1; //Enable H->L
LCD_en = 0;
LCD_busy(); //Wait for LCD to process the command
LCD_data = 0x06; //Entry mode, auto increment with no shift
LCD_rs = 0; //Selected command register
LCD_rw = 0; //We are writing in data register
LCD_en = 1; //Enable H->L
LCD_en = 0;
LCD_busy(); //Wait for LCD to process the command
}
void LCD_senddata(unsigned char var)
{
LCD_data = var; //Function set: 2 Line, 8-bit, 5x7 dots
LCD_rs = 1; //Selected data register
LCD_rw = 0; //We are writing
LCD_en = 1; //Enable H->L
LCD_en = 0;
LCD_busy(); //Wait for LCD to process the command
}
void LCD_command(unsigned char var)
{
LCD_data = var; //Function set: 2 Line, 8-bit, 5x7 dots
LCD_rs = 0; //Selected command register
LCD_rw = 0; //We are writing in instruction register
LCD_en = 1; //Enable H->L
LCD_en = 0;
LCD_busy(); //Wait for LCD to process the command
}
void LCD_sendstring(unsigned char var)
{
while(var) //till string ends
LCD_senddata(var++); //send characters one by one
}
void main()
{
TRISD = 0b00000000; //PORT D, RB0-2, RD7 for output.
LATD = 1;
TRISBbits.TRISB0 = 0; // Configures portB pin 0 to output
LATBbits.LATB0 = 1; // Set portB pin 0 to high; the latch register defines
TRISBbits.TRISB1 = 0; //the state sent to the port pin
LATBbits.LATB1 = 1;
TRISBbits.TRISB2 = 0;
LATBbits.LATB2 = 1;
TRISDbits.TRISD7 = 0;
LATDbits.LATD7 = 1;
ms40();
LCD_init();
LCD_command(0x83);
LCD_sendstring('HELLO WORLD...finally !!!');
}
Im trying to get a PIC18F458 dev board to say something, anything! I started first with a VFD and now have scaled back to a simple LED program.
Have 2 source codes. Can someone point out where the encoding is at fault and what it should be?
Appreciate.
LED:
//05-03-12 LED TOGGLE
#pragma code InterruptVectorHigh = 0x2008
#pragma code InterruptVectorLow = 0x2018
#pragma code main = 0x2020
#include "H:\PROGRAMS AND MCU'S\PIC\PIC 18 2376 PROJECT\header files\p18f458.h"
#include "H:\PROGRAMS AND MCU'S\PIC\PIC 18 2376 PROJECT\header files\delays.h"
#include "H:\PROGRAMS AND MCU'S\PIC\PIC 18 2376 PROJECT\header files\lcd.h"
#include "H:\PROGRAMS AND MCU'S\PIC\Microchip\mplabc18\v3.41\h\xlcd.h"
#define key PORTDbits.RD1 /* PORT for key */
#define TRIS_key TRISDbits.TRISD1 /* TRIS for key */
void delay (void)
{
Delay10KTCYx(100);
}
void toggle(void)
{
if(LATB == 0xff)
LATB = 0;
else
LATB = 0xFF;
while(key) delay();
}
void main (void)
{
/* Make all bits on the Port B (LEDs) output bits.
/* If bit is cleared, then the bit is an output bit.
*/
TRISB = 0;
TRIS_key =1;
while (1)
{
if(key == 1) toggle();
}
}
VFD:
// 3.5-LCD-VFD 04-thur12-12.
// The following program requires the pic18f458 MCU to send to a noritake
// Vacuum Fluorescent Display (model: CU20045-UW5A)the basic "Hello World" character
// string.
#pragma config OSC = HS, OSCS = ON
#pragma config BORV = 45, PWRT = ON, BOR = ON
#pragma config WDT = ON
#pragma config DEBUG = ON, LVP = ON, STVR = ON
#include<p18f458.h>
#define LCD_data PORTD
#define LCD_rs PORTBbits.RB0
#define LCD_rw PORTBbits.RB1
#define LCD_en PORTBbits.RB2
#define LCD_D7 PORTDbits.RD7
void ms40();
void LCD_busy();
void LCD_init();
void LCD_senddata(unsigned char var);
void LCD_command(unsigned char var);
void LCD_sendstring(unsigned char var);
void ms40()
{
int i;
for(i=0;i<9000;i++);
}
void LCD_busy()
{
TRISDbits.TRISD7 = 1; // Configure port pin D7 for input
LCD_D7 = 1; //Make D7th bit of LCD as i/p
LCD_en = 1; //Make port pin as o/p
LCD_rs = 0; //Selected command register
LCD_rw = 1; //We are reading
while(LCD_D7) //read busy flag again and again till it becomes 0
{
LCD_en = 0; //Enable H->L
LCD_en = 1;
}
TRISDbits.TRISD7 = 0; // Configure port pin D7 for output
}
void LCD_init()
{
LCD_data = 0x38; //Function set: 2 Line, 8-bit, 5x7 dots
LCD_rs = 0; //Selected command register
LCD_rw = 0; //We are writing in data register
LCD_en = 1; //Enable H->L
LCD_en = 0;
LCD_busy(); //Wait for LCD to process the command
LCD_data = 0x0F; //Display on, Curson blinking command
LCD_rs = 0; //Selected command register
LCD_rw = 0; //We are writing in data register
LCD_en = 1; //Enable H->L
LCD_en = 0;
LCD_busy(); //Wait for LCD to process the command
LCD_data = 0x01; //Clear LCD
LCD_rs = 0; //Selected command register
LCD_rw = 0; //We are writing in data register
LCD_en = 1; //Enable H->L
LCD_en = 0;
LCD_busy(); //Wait for LCD to process the command
LCD_data = 0x06; //Entry mode, auto increment with no shift
LCD_rs = 0; //Selected command register
LCD_rw = 0; //We are writing in data register
LCD_en = 1; //Enable H->L
LCD_en = 0;
LCD_busy(); //Wait for LCD to process the command
}
void LCD_senddata(unsigned char var)
{
LCD_data = var; //Function set: 2 Line, 8-bit, 5x7 dots
LCD_rs = 1; //Selected data register
LCD_rw = 0; //We are writing
LCD_en = 1; //Enable H->L
LCD_en = 0;
LCD_busy(); //Wait for LCD to process the command
}
void LCD_command(unsigned char var)
{
LCD_data = var; //Function set: 2 Line, 8-bit, 5x7 dots
LCD_rs = 0; //Selected command register
LCD_rw = 0; //We are writing in instruction register
LCD_en = 1; //Enable H->L
LCD_en = 0;
LCD_busy(); //Wait for LCD to process the command
}
void LCD_sendstring(unsigned char var)
{
while(var) //till string ends
LCD_senddata(var++); //send characters one by one
}
void main()
{
TRISD = 0b00000000; //PORT D, RB0-2, RD7 for output.
LATD = 1;
TRISBbits.TRISB0 = 0; // Configures portB pin 0 to output
LATBbits.LATB0 = 1; // Set portB pin 0 to high; the latch register defines
TRISBbits.TRISB1 = 0; //the state sent to the port pin
LATBbits.LATB1 = 1;
TRISBbits.TRISB2 = 0;
LATBbits.LATB2 = 1;
TRISDbits.TRISD7 = 0;
LATDbits.LATD7 = 1;
ms40();
LCD_init();
LCD_command(0x83);
LCD_sendstring('HELLO WORLD...finally !!!');
}