how to read/write to the internal eprom of PIC16F877 using PICBASIC

Status
Not open for further replies.

pouchito

New Member
Hello All,

Please i need your help to do the following.

need to add a number xxx.x with a number 0< n< 1 ( which will be calculated previously) and display the result on the LCD.

I need to write it using PICBASIC

i think my problem is with floating i m not getting correct result,
can anyone help me ?

Thanks in advance
 
Last edited:
From what I gathered, perhaps this is what your looking for?

Written with **broken link removed**


Code:
Device = 16F628A

Dim Variable1 As Float
Dim Variable2 As Float

Low PORTB.0

While 1 = 1
    Variable1 = Variable1 - 0.050
    EWrite 0, [Variable1]
    
    Variable2 = ERead 0 
    
    RSOut Dec Variable2, 13

    DelayMS 1000
Wend

Keep in mind that each float will require 4 bytes of memory, and they are not the best solution by any means for most applications
 

Attachments

  • EEPROM.PNG
    13.8 KB · Views: 2,618
Last edited:
Thanks a lot Gramo, but still need your help if possible.

need to modify your program to do the following.

I have a number n1n2n3.n4 saved on the internal ROM of the PIC

I need to read it and add it to a number which must be between 0and 1
let me call it x . this number will be entered to the pic. in my first trial i can assume that it s a fix number let s take it 0.2

and then the final summation n1n2n3.n4 + x will be saved on the ROm on the same location of the previous n1n2n3.n4 and displayed on the LCD

my main problem is how to store the n1n2n3.n4 , i must store each digit alone? n1 on one address n2 on another and so on ....?


PLease i need your help.
 
also i m confused , i know this is a stupid question! but i want to be sure

n1n2n3.n4 is a decimal number

this number can be defined as float?

i don't know what is float exactly !!!
byte = 4 bit ex 0000
word = 16 bit = 2 bytes ex 0000 0000
long word = 32 bits = 4 bytes ex 0000 0000 0000 0000


please correct my information!
thanks
 
Here's a common list of variable types for most micro controller compilers (this list is from Swordfish);
**broken link removed**

If you declare a number as a float, it can be used as a normal number with 3 decimal place accuracy. Keep in mind that floats take a lot of code overhead to really make them a viable option in most applications.

What is the maximum and minimum possible values that will be stored in the float? Perhaps I can show you much faster way to go about things.
 
pouchito said:
thanks again.
well maximum number will be 199.99

Well if you scale it (x100) the maximum value will only be 19999, so it will fit in a word variable, be a LOT faster, and be 100% accurate (floats aren't always accurate).
 
i need to show the decimal value, how can this be done
and i want always to get the result of this form

xxx.xx

pls i need your help
 
pouchito said:
i need to show the decimal value, how can this be done
and i want always to get the result of this form

Like I said, scale it, do it as an integer (faster, smaller, more accurate), simply put the decimal point back in place when you display it.
 
can u help me writing the code in picbasic pro?
i m a newbie in this language and need some help.

thanks in advance
 
pouchito said:
can u help me writing the code in picbasic pro?
i m a newbie in this language and need some help.

Sorry, I don't use BASIC, but what EXACTLY are you trying to do?.
 
well i need to perform an addition between a number of the form xxx.xx (saved on the internal eprom )and a number which will be entered to the pic (between 0 and 1 )
the result of the operation will be displayed on the LCD + saved on the eprom of the form xxx.xx

i must write it using picbasic pro cz i have other part to add to it and assembly will take me lot of time to do...
 
Have you seen the more than comprehensive help file with the compiler? I really suggest that you start with the basics of integer math, see how things "click" and then use the same analogy to use scale integer math as a replacement too using floats
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…