Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

PIC18F452 Working Problem

Status
Not open for further replies.
Thanks a lot for everything, I will try it in hardware and report back to you.

Side question:
How hard could it be to display the numbers in LCD instead of 7 segment, a 4 lines LCD
 

LCD will be very easy. The code will become very small.
 

I am making a 40x4 HD44780 compatible LCD library for mikroC PRO PIC Compiler. If I succeed you can use my library with a 40x4 LCD. Also I am making 2 versions of library. One will use 4 bit LCD and another will use I2C. I2C version needs only two lines.
 

Another option for you. You can use my I2C LCD library. With it you can have DS1307 and 7 x 20x4 LCDs in your project and 7 LCDs can display a lot of data.

Remember, you have to set the address of I2C LCD properly. This has to be set on I2C LCD module.

For I2C LCD codes for PIC and AVR see my projects here.

https://www.edaboard.com/threads/333263/

https://www.edaboard.com/threads/332743/

https://www.edaboard.com/threads/332348/

https://www.edaboard.com/threads/331854/

Also, you can use Big Fonts as shown here. It is a working code that somebody has done. I have tested it.

https://www.mikroe.com/forum/viewtopic.php?f=13&t=32369

If you want I can modify it so that it works with my I2C LCD library. You can display 2 datas on one LCD and so you will be able to display 14 datas on 7 LCDs. They just require 2 pins. The same I2C pins connected to DS1307.
 

Another option for you. You can use my I2C LCD library. With it you can have DS1307 and 7 x 20x4 LCDs in your project and 7 LCDs can display a lot of data.

Remember, you have to set the address of I2C LCD properly. This has to be set on I2C LCD module.

For I2C LCD codes for PIC and AVR see my projects here.

https://www.edaboard.com/threads/333263/

https://www.edaboard.com/threads/332743/

https://www.edaboard.com/threads/332348/

https://www.edaboard.com/threads/331854/

Also, you can use Big Fonts as shown here. It is a working code that somebody has done. I have tested it.

https://www.mikroe.com/forum/viewtopic.php?f=13&t=32369

If you want I can modify it so that it works with my I2C LCD library. You can display 2 datas on one LCD and so you will be able to display 14 datas on 7 LCDs. They just require 2 pins. The same I2C pins connected to DS1307.

I'm trying to do it using LCD, but using only one 4 line LCD, I'm facing a problem with the LCD_Initi() library, attached my code and proteus simulation.

I want to display 2 readings every 10 seconds so that all the 14 reading will be displayed with a timed delay between each two displays.

I don't know if this is possible, can you check my code to see why it's not getting my LCD initialization ?!

I would appreciate your help on this
 

Attachments

  • RTC DS1307 - Copy.rar
    167.3 KB · Views: 47

Do as I have done for month == 1 code. Do similar for other months in the while(1) loop. I hope it will solve your problem. Make changes and post the complete project here.

Move the
Code:
LCD_Out()
outside the
Code:
if(month == x) {... }
conditions so that you have to call the
Code:
LCD_Out()
functions for all variables only once that is if you have 6 variables to display, you have to call the function only six times outside the if() conditions.
 

Attachments

  • RTC DS1307 rev3.rar
    167.6 KB · Views: 45
Last edited:

Do as I have done for month == 1 code. Do similar for other months in the while(1) loop. I hope it will solve your problem. Make changes and post the complete project here.

Move the
Code:
LCD_Out()
outside the
Code:
if(month == x) {... }
conditions so that you have to call the
Code:
LCD_Out()
functions for all variables only once that is if you have 6 variables to display, you have to call the function only six times outside the if() conditions.

I did remove all lcd out from if statements and put lcd out after the if statements, still getting an error and the LCD won't display anything.

it doesn't even compile
 

Attachments

  • Captureسس.JPG
    Captureسس.JPG
    39.7 KB · Views: 58

In the 7 Segment displays version the segments used to display date and time always showed 88 88 88, 88 88 88 for me. I think your RTC is not running. First fix the RTC code and make the clock run in 7 Segment code and then convert it to LCD version. I am working on your code but it will take some time.
 

In the 7 Segment displays version the segments used to display date and time always showed 88 88 88, 88 88 88 for me. I think your RTC is not running. First fix the RTC code and make the clock run in 7 Segment code and then convert it to LCD version. I am working on your code but it will take some time.

Attached the lase code I'm working on, I tried to display the arrays isha, zoher and others in LCD but it displayed nothing, even though it takes the values from an array !!
 

Attachments

  • Pray.zip
    122.3 KB · Views: 37

If arrays are declared as const then they reside in ROM. As you have less RAM you have to put all your arrays in ROM and then when needed you have to take the required array into RAM.
 

If arrays are declared as const then they reside in ROM. As you have less RAM you have to put all your arrays in ROM and then when needed you have to take the required array into RAM.

Is this the reason why non of the values is displayed in the LCD ?!
 

I don't know how mikroC treated const type but in mikroC PRO if variable is declared as const trype then it is stored in ROM and you have to use
Code:
CopyConst2Ram()
function to bring the const values to RAM.

I have used
Code:
CopyConst2Ram()
with strings but have not used it with 2D or 3D arrays.

Can you instead switch your PIC to PIC18F46K22 ? If has more ROM and RAM. It also has 4 ports . So, there will be no need to make changes in code if you can use PIC18F46K22 and I think all the arrays can be stored in RAM itself. If you say yes, then I will change the circuit and test for new device.
 

I don't know how mikroC treated const type but in mikroC PRO if variable is declared as const trype then it is stored in ROM and you have to use
Code:
CopyConst2Ram()
function to bring the const values to RAM.

I have used
Code:
CopyConst2Ram()
with strings but have not used it with 2D or 3D arrays.

Can you instead switch your PIC to PIC18F46K22 ? If has more ROM and RAM. It also has 4 ports . So, there will be no need to make changes in code if you can use PIC18F46K22 and I think all the arrays can be stored in RAM itself. If you say yes, then I will change the circuit and test for new device.

In this code I used a function to turn the char array to int array and display it in the LCD, it did display numbers I don't know how accurate this is, but I don't know if it is actually a ROM and RAM problem.

I only have PIC18F452, I wish I can have others, I'm just trying to show the time for each individual:

fager
shrouq
zoher
aser
maghreb
isha
 

Attachments

  • Pray.zip
    149.6 KB · Views: 40

At the end of the code I see that RC0 to RC6 are used in the code. They are being assaigned values like 1 and 0 in the if() conditions but I also see that RC3 and RC4 are used for I2C for RTC. Where did you get the mikroC project from. Post the link for the original project.

Also I don't see the purpose of those big arrays because only a few elements of the arrays are used in
Code:
if(month == x) { ... }
conditions.

Maybe they compiled the code for a working project and generated the .hex file and then modified the code so that it doesn't work and then posted the .hex and project files.

I am working on your project but I need 1 or 2 days.

If
Code:
const double = 1.2;
is declared then the value will be in RAM but fixed and cannot be changed but I don't know where mikroC PRO stores const 2D arrays.

Remember, you have to extend the below arrays by one element

fager
shrouq
zoher
aser
maghreb
isha

and then make the last element null character to make the array a string and then pass it to
Code:
LCD_Out()
function otherwise you will get garbage characters on LCD.
 
Last edited:

At the end of the code I see that RC0 to RC6 are used in the code. They are being assaigned values like 1 and 0 in the if() conditions but I also see that RC3 and RC4 are used for I2C for RTC. Where did you get the mikroC project from. Post the link for the original project.

Also I don't see the purpose of those big arrays because only a few elements of the arrays are used in
Code:
if(month == x) { ... }
conditions.

Maybe they compiled the code for a working project and generated the .hex file and then modified the code so that it doesn't work and then posted the .hex and project files.

I am working on your project but I need 1 or 2 days.

If
Code:
const double = 1.2;[/code is declared then the value will be in RAM but fixed and cannot be changed but I don't know where mikroC PRO stores const 2D arrays.[/QUOTE]

Attached the original project 
it is made using PIC16F877A
I mixed it with the original 7segment code, and used PIC18F452
 

Attachments

  • Digital Clock.rar
    307.6 KB · Views: 43

My previous post is updated. Read it and reply. Please zip and post the original 7 segment project which worked and which displays

fager
shrouq
zoher
aser
maghreb
isha

Each element of

fager
shrouq
zoher
aser
maghreb
isha

should only contain values 0 to 9. If that is done then it can be easily converted to ascii character by adding 48 and then the array terminated with a null character and sent to
Code:
LCD_Out()
. If the elements of these arrays contain something like 58, 42, etc... then a seperate piece of code has to be written to convert the values of these arrays to string.

If 7 Segment code works then my advice is to use the 7 Segment Circuit only.


Edit

Isn't there a formula to calculate

fager
shrouq
zoher
aser
maghreb
isha

values for each month from date and time of RTC ? If there is one then provide it here.

Remember in your code all the date and time variables contain BCD values from RTC. If you want date and time values to be displayed on LCD then you have to transform date and time values from RTC.

Have you checked RTC2 Click example at libstock.com ?

- - - Updated - - -

I think this will solve your problem of accessing const arrays from ROM.

https://www.mikroe.com/forum/viewtopic.php?f=88&t=55186
 
Last edited:

My previous post is updated. Read it and reply. Please zip and post the original 7 segment project which worked and which displays

fager
shrouq
zoher
aser
maghreb
isha

Each element of

fager
shrouq
zoher
aser
maghreb
isha

should only contain values 0 to 9. If that is done then it can be easily converted to ascii character by adding 48 and then the array terminated with a null character and sent to
Code:
LCD_Out()
. If the elements of these arrays contain something like 58, 42, etc... then a seperate piece of code has to be written to convert the values of these arrays to string.

If 7 Segment code works then my advice is to use the 7 Segment Circuit only.


Edit

Isn't there a formula to calculate

fager
shrouq
zoher
aser
maghreb
isha

values for each month from date and time of RTC ? If there is one then provide it here.

Remember in your code all the date and time variables contain BCD values from RTC. If you want date and time values to be displayed on LCD then you have to transform date and time values from RTC.

Have you checked RTC2 Click example at libstock.com ?

- - - Updated - - -

I think this will solve your problem of accessing const arrays from ROM.

https://www.mikroe.com/forum/viewtopic.php?f=88&t=55186

This is a code that calculate using the time from RTC using Formulas, attached it's proteus design and hex file, don't really now what kind of compiler it's written by.

Code:
'
' *

program prayartime


dim y ,L1 as longint
dim D,L,ty,Lambda,Obliquity ,Alpha,ST,Dec1,noon, utnoon,dhrtime,asrtime,asralt,durinalarc,marbtime,EshaArc,M,eshatime,fajrtime,shroq ,ard,tol as float
    i ,farq   as byte
    day,month_,dhr,dhr1,asr,asr1,fjr,fjr1,marb,marb1,esha,esha1 as byte
    dim x,x1 as byte[48]
sub procedure awqat()

ard=36.334
tol=43.2
farq=3
D=((367*y)-(floor((1.75)*(y+floor((month_+9)/12))))+floor(275*(month_/9))+day-730531.5)
L=280.461+0.9856474*D
 L1=L
 L=L-L1
 L1=L1 mod 360
 L=L1+L
 M = 357.528+0.9856003*D
  L1=M
  M=M-L1
  L1=L1 mod 360
  M=L1+M
Obliquity = 23.439-0.0000004*D
Lambda = L+1.915*sin(M*PI/180)+0.02*sin(2*M*PI/180)
  L1=Lambda
  Lambda =Lambda-L1
  L1=L1 mod 360
  Lambda =L1+Lambda
Alpha=atan(cos(Obliquity *PI/180)*tan(Lambda*PI/180))*180/PI
Alpha=Alpha-(360*floor(Alpha/360))
Alpha=Alpha+90*(floor(Lambda/90)-floor(Alpha/90))
 ST=100.46 + 0.985647352 *D
 L1=ST
  ST=ST-L1
  L1=L1 mod 360
  ST=L1+ST
  Dec1=asin(sin(Obliquity*PI/180)*sin(Lambda*PI/180))*180/PI
  noon=Alpha-ST
  if noon>=0 then
  noon=fabs(noon)
  L1=fabs(noon)
  noon=noon-L1
  L1=L1 mod 360
  noon=noon+L1
  else
  noon=fabs(noon)
  L1=fabs(noon)
  noon=noon-L1
  L1=L1 mod 360
  noon=noon+L1
  noon=360-noon
  end if
   utnoon=noon-tol
  dhrtime=(utnoon/15)+farq
  dhr1=dhrtime
  dhrtime=dhrtime-dhr1
 dhr=floor(dhrtime*60)
 dhrtime=(utnoon/15)+3
   asralt=atan(1+tan((ard-Dec1)*PI/180))*180/PI
  asrtime=acos((sin((90-asralt)*PI/180)-sin(Dec1*PI/180)*sin(ard*PI/180))/(COS(Dec1*PI/180)*COS(ard*PI/180)))*180/PI
 asrtime=(asrtime/15)+dhrtime

 asr1=asrtime
 asrtime=asrtime-asr1
 asr=floor(asrtime*60)
 durinalarc=acos((SIN(-0.8333*PI/180)-SIN(Dec1*PI/180)*SIN(ard*PI/180))/(COS(Dec1*PI/180)*COS(ard*PI/180)))*180/PI
 shroq=dhrtime-durinalarc/15

   marbtime=dhrtime+durinalarc/15
   marb1=marbtime
  marbtime=marbtime-marb1
 marb=floor(marbtime*60)
 EshaArc= acos((SIN(-18*PI/180)-SIN(Dec1*PI/180)*SIN(ard*PI/180))/(COS(Dec1*PI/180)*COS(ard*PI/180)))*180/PI
 eshatime=dhrtime+EshaArc/15
 esha1=eshatime
 eshatime=eshatime-esha1
 esha=floor(eshatime*60)
 fajrtime=dhrtime-EshaArc/15
  fjr1=fajrtime
  fajrtime=fajrtime-fjr1
  fjr=floor(fajrtime*60)
dhr=dec2bcd(dhr)
dhr1=dec2bcd(dhr1)
fjr=dec2bcd(fjr)
fjr1=dec2bcd(fjr1)
if asr1>12 then
asr1=asr1-12
end if
if marb1>12 then
marb1=marb1-12
end if
if esha1>12 then
esha1=esha1-12
end if              '
asr=dec2bcd(asr)
asr1=dec2bcd(asr1)
marb=dec2bcd(marb)
marb1=dec2bcd(marb1)
esha=dec2bcd(esha)
esha1=dec2bcd(esha1)
end sub
dim Soft_I2C_Scl               as sbit at RC3_bit
dim Soft_I2C_Sda               as sbit at RC4_bit
dim Soft_I2C_Scl_Direction as sbit at TRISC3_bit
dim Soft_I2C_Sda_Direction as sbit at TRISC4_bit
  dim sec,min,hr,week_day,dday,mn,year as short
sub procedure Read_Time(dim byref sec, min, hr, week_day, dday, mn, year as short)

    Soft_I2C_Start()
    Soft_I2C_Write(0xD0)
    Soft_I2C_Write(0)
    Soft_I2C_Start()
    Soft_I2C_Write(0xD1)
    sec =Soft_I2C_Read(1)
    min =Soft_I2C_Read(1)
    hr =Soft_I2C_Read(1)
    week_day =Soft_I2C_Read(1)
    dday =Soft_I2C_Read(1)
    mn =Soft_I2C_Read(1)
    year =Soft_I2C_Read(0)
    Soft_I2C_Stop()
end sub


sub procedure Write_Time(dim address1 as short,dim data_wr as short)
    Soft_I2C_Start()
    Soft_I2C_Write(0xD0)
    Soft_I2C_Write(address1)
    Soft_I2C_Write(data_wr)
    Soft_I2C_Stop()
    end sub
'
main:
  TRISB = 0
  PORTB = 0
  trisc.0=0
  trisc.1=0
  trisc.2=0
  trisa.0=0
  Soft_I2C_Init()
  while true
  Read_Time(sec,min,hr,week_day,dday,mn,year)
  day=bcd2dec(dday)
  month_=bcd2dec(mn)
  y=2010
  awqat()

   for i=0 to 47
   x[i]=0
   x1[i]=0
   next i
  for i = 0 to 7
   x[i]=dhr.i
   x1[i]=esha.i
  next i
   for i = 0 to 7
   x[i+8]=dhr1.i
   x1[i+8]=esha1.i
  next i
   for i = 0 to 7
   x[i+16]=fjr.i
   x1[i+16]=marb.i
  next i
   for i = 0 to 7
   x[i+24]=fjr1.i
   x1[i+24]=marb1.i
  next i
   for i = 0 to 7
   x[i+32]=min.i
   x1[i+32]=asr.i
  next i
  for i = 0 to 7
   x[i+40]=hr.i
   x1[i+40]=asr1.i
  next i
  for i = 0 to  47
   portb.0=x[i]
   portc.0=x1[i]
   portb.1=0
   portc.1=0
   delay_us(20)
   portb.1=1
   portc.1=1
   next i
   porta.0=1
   delay_ms(300)
   portb.2=0
   portc.2=0
   delay_us(20)
   portb.2=1
   portc.2=1
   porta.0=0
   delay_ms(300)
  wend
end.


If you can make it display the values in LCD instead of 7 Segment I would appreciate it.

Regarding the original code for the previous 7 segment design using mikroC complier it is also attached named "New folder"

I will try your suggestions, appreciate your help
 

Attachments

  • prayer_2.rar
    40.5 KB · Views: 39
  • New folder.rar
    359.1 KB · Views: 60

I can easily tell that it is mikroBasic Code for PIC but maybe it is either mikroBasic v7.2 for PIC or mikroBasic PRO PIC code. Please try to create a new mikroBasic project in mikroBasic PRO PIC and try to compiler the code for the original device used for that code. I will also try.

Can you provide the link from where you got that code ?

- - - Updated - - -

Here is the mikroBasic PRO PIC project. LCD code has to be implemented. I have changed names of two variables because those names were already used in library functions.
 

Attachments

  • Prayer Time mikroBasic PRO PIC Project.rar
    108.5 KB · Views: 59

I can easily tell that it is mikroBasic Code for PIC but maybe it is either mikroBasic v7.2 for PIC or mikroBasic PRO PIC code. Please try to create a new mikroBasic project in mikroBasic PRO PIC and try to compiler the code for the original device used for that code. I will also try.

Can you provide the link from where you got that code ?

- - - Updated - - -

Here is the mikroBasic PRO PIC project. LCD code has to be implemented. I have changed names of two variables because those names were already used in library functions.

This is the original thread link https://www.qariya.info/vb/showthread.php?t=64124

I will try the code an get back to u
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top