Hi,
I have been try the experiments from rajbex and am currently trying to implement his latest experiment into my project.
I want to set a number in the eeprom and can do this thanks to rajbex. however if I want to change that number I am having difficulties.
I have the following code:
The above code does work and when pressing the corresponding button the number is incresed or decreased, however I can only display numbners 0 - 9. I am led to believe that the next number 10 is being stored but I need to seperate it and display 1+48 and 0+48. How can I do this? Also I would like to be able to store and display negative numbers as I need a scale of -55 to +125
Thanks
I have been try the experiments from rajbex and am currently trying to implement his latest experiment into my project.
I want to set a number in the eeprom and can do this thanks to rajbex. however if I want to change that number I am having difficulties.
I have the following code:
Code:
/*
Project Name: Read/Write Internal EEPROM
* Copyright:
(c) Rajendra Bhatt, 2009.
* Description:
This code is an example of accessing internal EEPROM.
* Test configuration:
MCU: PIC16F628
Oscillator: IntRC I/O
*/
// LCD connections definitions
sbit LCD_RS at RA0_bit;
sbit LCD_EN at RA1_bit;
sbit LCD_D4 at RB0_bit;
sbit LCD_D5 at RB1_bit;
sbit LCD_D6 at RB2_bit;
sbit LCD_D7 at RB3_bit;
sbit LCD_RS_Direction at TRISA0_bit;
sbit LCD_EN_Direction at TRISA1_bit;
sbit LCD_D4_Direction at TRISB0_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D7_Direction at TRISB3_bit;
// End LCD connections definitions
// Define Messages
char message1[] = "1.READ";
char message2[] = "2.INC";
char message3[] = "3.DEC";
char message4[] = "Set Temp:";
char digits[] = "0";
unsigned short i, NUM ;
unsigned int ADD = 0x00, temp; // Start EEPROM Location
void main() {
CMCON |= 7; // Disable Comparators
TRISB = 0x0F;
PORTB = 0x00;
Lcd_Init();
start:
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off
Lcd_Out(1,1,message1); // Write message1 in 1st row
Lcd_Out(1,8,message2);
Lcd_Out(2,1,message3);
do {
// Read Operation
if (Button(&PORTA, 2, 1, 0)) { // Detect logical one to zero
Delay_ms(300);
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(1,1,message4);
NUM = EEPROM_Read(0x000);
digits[0] = NUM+48;
Lcd_Out(2,1,digits);
delay_ms(1000);
goto start;
}
//increment
if (Button(&PORTA, 3, 1, 0)) { // Detect logical one to zero
NUM = EEPROM_Read(0x000)+1;
EEPROM_Write(0x000,NUM);
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(1,1,message4);
digits[0] = NUM+48;
Lcd_Out(2,1,digits);
delay_ms(1000);
goto start;
}
//decrement
if (Button(&PORTA, 4, 1, 0)) { // Detect logical one to zero
NUM = EEPROM_Read(0x000)-1;
EEPROM_Write(0x000,NUM);
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(1,1,message4);
digits[0] = NUM+48;
Lcd_Out(2,1,digits);
delay_ms(1000);
goto start;
}
} while(1);
}
The above code does work and when pressing the corresponding button the number is incresed or decreased, however I can only display numbners 0 - 9. I am led to believe that the next number 10 is being stored but I need to seperate it and display 1+48 and 0+48. How can I do this? Also I would like to be able to store and display negative numbers as I need a scale of -55 to +125
Thanks