EEPROM to store 1000

LED Blinking, Walking with Cytron Servo, Displaying RFID, Multi-function Mobile Robot......

EEPROM to store 1000

Postby silveroblado » Mon Sep 12, 2011 10:44 am

CODE: SELECT_ALL_CODE
void store_EEPROM(unsigned char data, unsigned char location);         //eeprom
unsigned char get_EEPROM(unsigned char location);

unsigned char reverse=0;         
unsigned char blackspot=0x00;           //location in eeprom//memory map

unsigned char crack;
unsigned char y;
unsigned char z=0;

unsigned char thousand;
unsigned char hundred;
unsigned char tenth;
unsigned char unit;

void main(void)
{
   TRISA = 0b00000011;               //configure PORTA I/O direction
   TRISB = 0b00000000;               //configure PORTB I/O direction
   TRISC = 0b00000000;   
    TRISD = 0b00000000;
    TRISE = 0b00000000;

    PORTA = 0x00;                      //clearing all ports before use
    PORTB = 0x00;
    PORTC = 0x00;
    PORTD = 0x00;
    PORTE = 0x00;
 
    CMCON = 0x07;                     //disable all the comparators
   ADCON1 = 0x06;                  //configure PORTA as digital I/O

   send_config(0b00000001);         //clear display at lcd
   send_config(0b00000010);         //lcd return to home
   send_config(0b00000110);         //entry mode-cursor increase 1
   send_config(0b00001100);         //display on, cursor off and cursor blink off
   send_config(0b00111000);


   thousand = countAB / 1000;
   countAB = countAB % 1000;
   hundred = countAB / 100;
   countAB = countAB % 100;
   tenth = countAB / 10;
   unit = countAB % 10;
   
    CCP1CON = 0b00001100;
   CCP2CON = 0b00001100;            
   PR2 = 0xFF;                     //PWM Period Setting (4.88KHz)
    T2CON = 0b00000101;      

While(1)
{

if(LSS05==1 && reverse ==0)                           //when LSS05 detects black spot
              {   
                store_EEPROM(thousand,blackspot);
                store_EEPROM(hundred,blackspot+1);
                store_EEPROM(tenth,blackspot+2);   
                store_EEPROM(unit,blackspot+3);
                   buzzer=1;                           //buzzer will make noise for 100Us then off
                   DelayUs(1000);
                   buzzer=0;
                blackspot+=0x10;             
              }


if(countAB==0)            //when countAB reaches 0
                       {
                           
                           lcd_clr();
             
                           for(y=0x00;y<0x04;y++)
                           {
                           crack=get_EEPROM(y);
                           lcd_goto(z);
                           send_char(crack);
                           z+=1;
                           }
                           
                           z+=1;
                           for(y=0x10;y<0x14;y++)
                           {
                           crack=get_EEPROM(y);
                           lcd_goto(z);
                           send_char(crack);
                           z+=1;
                           }

                           z+=1;
                           for(y=0x20;y<0x24;y++)
                           {
                           crack=get_EEPROM(y);
                           lcd_goto(z);
                           send_char(crack);
                           z+=1;
                           }
}

//============================================================================================================================
//             EEPROM FUNCTION
//============================================================================================================================

//store data into specified loaction in EEPROM
void store_EEPROM(unsigned char data, unsigned char location)
{
EEPROM_WRITE(location,data);    //write data
while(WR)                        //wait until it finish
continue;
}

//============================================================================================================================

//access EEPROM to retrieve data
unsigned char get_EEPROM(unsigned char location)
{
unsigned char value;
value= EEPROM_READ(location);                    //read eeprom and assign the data to variable
return value;                                    //return data
}

//============================================================================================================================
silveroblado
Apprentice
 
Posts: 32
Joined: Mon Aug 15, 2011 2:30 am
Location: Kuala Lumpur

Re: EEPROM to store 1000

Postby silveroblado » Mon Sep 12, 2011 10:52 am

This is just a part of code!!I did not put full code here as according to cytron rules!!What is happening in code is when LSS05 detects a blackspot, the value of the countAB which I get from rotary encoder is stored in eeprom!!I have 3 spots to detect!!so when the 1 spot is detected its stored at 0x00,then second on 0x10 then third on 0x20!

When the PIC proces finishes, when countAB reaches zero!!The value from eeprom is got and displayed on the LCD!!all the 3 values togather!!each value is of max 4 numbers!!e.g 2000, 4000, 9000!!

Plz see if the concept is correct!!and can it work!!bcoz in proteus i cant make it work!
silveroblado
Apprentice
 
Posts: 32
Joined: Mon Aug 15, 2011 2:30 am
Location: Kuala Lumpur

Re: EEPROM to store 1000

Postby yonghui » Mon Sep 12, 2011 5:03 pm

hi,

i hope u can see there is a button "Code" above the editor when u writing your post. if u wan to post lengthy code, pls use highlight you code and click the Code button.



CODE: SELECT_ALL_CODE
code 1
2
3
4
5
6
7
8
9
10



if u are using hi tech c compiler, u can refer to the hi tech c compiler manual for the eeprom function description. else if u are using others u can try to refer to the user manual on how to use the function. im not sure why u wan to save the number of spots u detected in eeprom.
mayb u can analyse ur problem 1st then post explanation on what goes wrong here. so that easier for us to know what is happening with ur project.


regards,
yh
thanks&regards,
yh
yonghui
Moderator
 
Posts: 732
Joined: Mon Sep 28, 2009 3:27 pm

Re: EEPROM to store 1000

Postby silveroblado » Mon Sep 12, 2011 5:53 pm

I m not storing the number of spots!!I m storing the value of counts from the rotary encoder when spots are detected!!so as to know the sitance from starting where spots were found!!
silveroblado
Apprentice
 
Posts: 32
Joined: Mon Aug 15, 2011 2:30 am
Location: Kuala Lumpur

Re: EEPROM to store 1000

Postby shiyan » Tue Sep 13, 2011 11:45 pm

yes, you din paste entire of your code, still none of us is code checker, at least not me 8-), furthermore, I am not Cytron staff, and not familiar with LSS, so please explain clearly. :mrgreen:
User avatar
shiyan
Amateur
 
Posts: 189
Joined: Wed Jun 09, 2010 10:59 am

Re: EEPROM to store 1000

Postby yonghui » Wed Sep 14, 2011 12:24 am

hi,

which compiler u are using?



regards,
yh
thanks&regards,
yh
yonghui
Moderator
 
Posts: 732
Joined: Mon Sep 28, 2009 3:27 pm

Re: EEPROM to store 1000

Postby silveroblado » Wed Sep 14, 2011 2:06 am

Hi-Tech C compiler......with PIC 16f877a.....SK40C
silveroblado
Apprentice
 
Posts: 32
Joined: Mon Aug 15, 2011 2:30 am
Location: Kuala Lumpur

Re: EEPROM to store 1000

Postby yonghui » Wed Sep 14, 2011 9:48 am

my suggestion is that u store the the value to eeprom, no need to convert to digit with these:

thousand = countAB / 1000;
countAB = countAB % 1000;
hundred = countAB / 100;
countAB = countAB % 100;
tenth = countAB / 10;
unit = countAB % 10;


when u wan to display to LCD then only u retrieve the value from LCD and convert to digit.
then when u get the digit, u add to '0' to get the ascii code of the digit. then only send to LCD. i dunno how u send_char function look like. mayb the function plays the role to convert to ascii code?


regards,
yh
thanks&regards,
yh
yonghui
Moderator
 
Posts: 732
Joined: Mon Sep 28, 2009 3:27 pm

Re: EEPROM to store 1000

Postby ober » Fri Sep 16, 2011 9:40 pm

I would advise you to develop the program part by part. Try the EEPROM write and read first. Just write value into EEPROM using the Write and Read from HiTECH library to verify it is working. Just display the value to LED or simple output. One bit is sufficient to verify it is working.

Then further write the data and read it and further display to LCD. Step by step.Don put everything into initial program, it is difficult to troubleshoot.
Ober Choo
Cytron Technologies Sdn Bhd
www.cytron.com.my
User avatar
ober
Moderator
 
Posts: 1486
Joined: Wed Apr 15, 2009 1:03 pm


Return to DIY Project Set

Who is online

Users browsing this forum: No registered users and 13 guests

cron