wad i gt here is a program tat receive characters from the hyper terminal, i m using PICDEM 2 PLUS DEMO BOARD. and this runs in either debbuger or programmer mode. wad my problem is how to save the characters i received into PIC's memory so tat i can double check on what is received. the data stored must b able to remain in the memory even when there is no power supply.i was hopin to use programmer mode rather den debugger mode. below is my program.
#include <p18f452.h>
void Init_LCD(void); // Initialize the LCD
void W_ctr_4bit(char); // 4-bit Control word for LCD
void W_data_4bit(char); // 4-bit Text Data for LCD
void Delay_1kcyc(void); // 1000 cycles delay
void Delay_100kcyc(void); // 100,000 cycles delay
void Init_com(void); // Initialize the Computer
#define LCD_DATA PORTD
#define LCD_RW PORTAbits.RA2 // RW signal for LCD
#define LCD_RS PORTAbits.RA3 // RS signal for LCD
#define LCD_E PORTAbits.RA1 // E signal for LCD
unsigned char LCD_TEMP;
unsigned char USART_TEMP;
void main(){
ADCON1 = 0x07; // Set Port A & E as digital I/O
TRISA = 0b11110001; // bit 1, 2 & 3 of Port A as output
TRISD = 0; // Port D as output
Init_LCD(); // Init LCD 4-bit interface, multiple line
Init_com(); // Init Com
while (1) //finite loop
{
if (PIR1bits.RCIF) //if PIR1 bit is RCIF
{
W_data_4bit(RCREG); //get char from hyper term and display
}
}
}
void Init_com(){
TRISC=0b10111111; // RX as input,TX as output
SPBRG=12; // Baud rate is 19200
TXSTA=0b00100100; // Asyn mode, 8-bit data
RCSTA=0b10010000; // serial port enable, 8-bit data
}
void Init_LCD(){ /* LCD display initialization */
//Sequence a) to d) required for 4-bit interface
for(i = 0; i < 15; i++) Delay_1kcyc(); // a)
W_ctr_4bit(0x03); // b)
for(i = 0; i < 5; i++) Delay_1kcyc(); // c)
W_ctr_4bit(0x02); // d)
W_ctr_4bit(0b00101000);
W_ctr_4bit(0b00001101); // Display on, cursor on
W_ctr_4bit(0b00000110);
W_ctr_4bit(0b00000001); // Clear display & home position
}
void W_ctr_4bit(char x){
/* Write control word in term of 4-bit at a time to LCD */
LCD_RW = 0; // Logic ‘0’
LCD_RS = 0; // Logic ‘0’
LCD_TEMP = x; // Store control word
LCD_TEMP >>= 4; // send upper nibble of control word
LCD_E = 1; // Logic ‘1’
LCD_DATA = LCD_TEMP;
Delay_1kcyc(); // 1ms delay
LCD_E = 0; // Logic ‘0’
Delay_1kcyc(); // 1ms delay
LCD_TEMP = x; // Store control word
LCD_TEMP &= 0x0f; // Send lower nibble of control word
LCD_E = 1; // Logic ‘1’
LCD_DATA = LCD_TEMP;
Delay_1kcyc(); // 1ms delay
LCD_E = 0; // Logic 0’
Delay_1kcyc(); // 1ms delay
}
void W_data_4bit(char x){
/* Write text data in term of 4-bit at a time to LCD */
LCD_RW = 0; // Logic ‘0’
LCD_RS = 1; // Logic ‘1’
LCD_TEMP = x; // Store text data
LCD_TEMP >>= 4; // Send upper nibble of text data
LCD_E = 1; // Logic ‘1’
LCD_DATA = LCD_TEMP;
Delay_1kcyc(); // 1ms delay
LCD_E = 0; // Logic ‘0’
Delay_1kcyc(); // 1ms delay
LCD_TEMP = x; // Store text data
LCD_TEMP &= 0x0f; // Send lower nibble of text data
LCD_E = 1; // Logic ‘1’
LCD_DATA = LCD_TEMP;
Delay_1kcyc(); // 1ms delay
LCD_E = 0; // Logic ‘0’
Delay_1kcyc(); // 1ms delay
}
void Delay_1kcyc(){
/* 1,000 cycles delay routine. For 1 4MHz crystal, it is 1ms delay */
unsigned int j;
for(j=0; j<65; j++);
}
post edited by boi^boi - 2006/04/05 20:37:34