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.

help me find error in program for PIC16F877A

Status
Not open for further replies.

Shoaib Khan

Newbie level 4
Newbie level 4
Joined
Feb 4, 2014
Messages
5
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
32
Code:
#define  hbit    portc.f0
#define  sw1    portd.f0


//==============================================
unsigned int adc_rd0;
  unsigned char ch;

 void     get_ad();
 void     get_hb();
 void  disp_hb();
long tlong;
unsigned char  cnt=0,indh=0,ind=0,cnt2=0;
//==============================================================
 unsigned int address;
 unsigned char d1a,d2a,d3a;
unsigned char d1b,d2b,d3b;
unsigned char d1c,d2c,d3c;
unsigned char d1,d2,d3;
void main()
{

   DELAY_MS(500);

ADCON1=0b00000110;


 Lcd_Custom_Config(&PORTB,7,6,5,4,&PORTB,2,0,3);
   Lcd_Custom_Cmd(Lcd_CURSOR_OFF);
   Lcd_Custom_Cmd(Lcd_Clear);

     ADCON1     = 0x82;                       // configure VDD as Vref, and analog channels
  TRISA      = 0xFF;                       // designate PORTA as input
  TRISD=0X00;
  trisc.f0=1;
  trisd.f0=1;

     Lcd_Custom_Out(1,2,"RIPAH INTERNATIONAL ");
  DELAY_MS(1000);
  Lcd_Custom_Cmd(Lcd_Clear);


      address =0;
      d1a=Eeprom_Read(address);
      address =1;
      d2a=Eeprom_Read(address);
      address =2;
      d3a=Eeprom_Read(address);
      
      
 address =3;
      d1b=Eeprom_Read(address);
      address =4;
      d2b=Eeprom_Read(address);
      address =5;
      d3b=Eeprom_Read(address);

 address =6;
      d1c=Eeprom_Read(address);
      address =7;
      d2c=Eeprom_Read(address);
      address =8;
      d3c=Eeprom_Read(address);


 //  Lcd_Custom_Out(2,2,"TEMPERATURE");
  while(1){
 if(sw1==0) {
     Lcd_Custom_Cmd(Lcd_Clear);
       address =0;
      d1a=Eeprom_Read(address);
      address =1;
      d2a=Eeprom_Read(address);
      address =2;
      d3a=Eeprom_Read(address);

  DELAY_MS(1000);

 address =3;
      d1b=Eeprom_Read(address);
      address =4;
      d2b=Eeprom_Read(address);
      address =5;
      d3b=Eeprom_Read(address);

 address =6;
      d1c=Eeprom_Read(address);
      address =7;
      d2c=Eeprom_Read(address);
      address =8;
      d3c=Eeprom_Read(address);

    Lcd_Custom_Chr(1,2,48+d1a);
    Lcd_Custom_Chr(1,3,48+d2a);
    Lcd_Custom_Chr(1,4,48+d3a);

    Lcd_Custom_Chr(1,10,48+d1b);
    Lcd_Custom_Chr(1,11,48+d2b);
    Lcd_Custom_Chr(1,12,48+d3b);

    Lcd_Custom_Chr(2,2,48+d1c);
    Lcd_Custom_Chr(2,3,48+d2c);
    Lcd_Custom_Chr(2,4,48+d3c);
      DELAY_MS(3000);
    while(sw1==0);
     Lcd_Custom_Cmd(Lcd_Clear);
  DELAY_MS(1000);



}//get_ad();
 get_hb();
//  Lcd_Custom_Cmd(Lcd_Clear);
  DELAY_MS(2000);

 disp_hb();
   DELAY_MS(2000);
// disp_hb();



                 }
         }
//==================================================

void disp_hb() {
 cnt=cnt*6;
     tlong=cnt;
      Lcd_Custom_Chr(1,1,'h');
    LCD_Custom_Chr_CP('b');
    LCD_Custom_Chr_CP('=');
    ch     = tlong / 1000;                 // extract volts digit
     Lcd_Custom_Chr(1,4,48+ch);

    ch    = (tlong / 100) % 10;            // extract 0.1 volts digit
    d1=ch;

     LCD_Custom_Chr_CP(48+ch);

    ch    = (tlong / 10) % 10;             // extract 0.01 volts digit
   d2=ch;
     LCD_Custom_Chr_CP(48+ch);
    ch    = tlong  % 10;             // extract 0.01 volts digit
   d3=ch;
     LCD_Custom_Chr_CP(48+ch);

cnt2++;
if(cnt2>3)cnt2=1;

if(cnt2==1){
          Eeprom_Write(0,d1 );
          Eeprom_Write(1,d2 );
          Eeprom_Write(2, d3);

}
if(cnt2==2){
          Eeprom_Write(3,d1 );
          Eeprom_Write(4,d2 );
          Eeprom_Write(5, d3);

}
if(cnt2==3){
          Eeprom_Write(6,d1 );
          Eeprom_Write(7,d2 );
          Eeprom_Write(8, d3);

}

}

void disp_hb2() { /////with out multiply
// cnt=cnt*6;
     tlong=cnt;
      Lcd_Custom_Chr(2,1,'h');
    LCD_Custom_Chr_CP('b');
    LCD_Custom_Chr_CP('=');
    ch     = tlong / 1000;                 // extract volts digit
     Lcd_Custom_Chr(2,4,48+ch);

    ch    = (tlong / 100) % 10;            // extract 0.1 volts digit

     LCD_Custom_Chr_CP(48+ch);

    ch    = (tlong / 10) % 10;             // extract 0.01 volts digit
     LCD_Custom_Chr_CP(48+ch);
    ch    = tlong  % 10;             // extract 0.01 volts digit
     LCD_Custom_Chr_CP(48+ch);



}


 void  get_hb() {
unsigned char  i=0,j=0;
 cnt=0;
   Lcd_Custom_Out(3,1,"                     ");
    Lcd_Custom_Chr(3,1,'>');
 for(j=0;j<30;j++) {
  delay_ms(100);
  disp_hb2();
 if(hbit==0) {
 cnt++;
while(hbit==0);
}



                    }



//
 }

  void  get_ad()
{

      adc_rd0  = ADC_read(0);
        Delay_ms(500);

    tlong = (long)adc_rd0 * 5000;
    tlong = tlong / 1023;

    ch     = tlong / 1000;                 // extract volts digit
    Lcd_Custom_Chr(1,10,48+ch);

    ch    = (tlong / 100) % 10;            // extract 0.1 volts digit
     LCD_Custom_Chr_CP(48+ch);
    ch    = (tlong / 10) % 10;             // extract 0.01 volts digit
     LCD_Custom_Chr_CP(48+ch);

        Delay_ms(500);
    LCD_Custom_Chr_CP('c');





}#define  hbit    portc.f0
#define  sw1    portd.f0


//==============================================
unsigned int adc_rd0;
  unsigned char ch;

 void     get_ad();
 void     get_hb();
 void  disp_hb();
long tlong;
unsigned char  cnt=0,indh=0,ind=0,cnt2=0;
//==============================================================
 unsigned int address;
 unsigned char d1a,d2a,d3a;
unsigned char d1b,d2b,d3b;
unsigned char d1c,d2c,d3c;
unsigned char d1,d2,d3;
void main()
{

   DELAY_MS(500);

ADCON1=0b00000110;


 Lcd_Custom_Config(&PORTB,7,6,5,4,&PORTB,2,0,3);
   Lcd_Custom_Cmd(Lcd_CURSOR_OFF);
   Lcd_Custom_Cmd(Lcd_Clear);

     ADCON1     = 0x82;                       // configure VDD as Vref, and analog channels
  TRISA      = 0xFF;                       // designate PORTA as input
  TRISD=0X00;
  trisc.f0=1;
  trisd.f0=1;

     Lcd_Custom_Out(1,2,"RIPAH INTERNATIONAL ");
  DELAY_MS(1000);
  Lcd_Custom_Cmd(Lcd_Clear);


      address =0;
      d1a=Eeprom_Read(address);
      address =1;
      d2a=Eeprom_Read(address);
      address =2;
      d3a=Eeprom_Read(address);
      
      
 address =3;
      d1b=Eeprom_Read(address);
      address =4;
      d2b=Eeprom_Read(address);
      address =5;
      d3b=Eeprom_Read(address);

 address =6;
      d1c=Eeprom_Read(address);
      address =7;
      d2c=Eeprom_Read(address);
      address =8;
      d3c=Eeprom_Read(address);


 //  Lcd_Custom_Out(2,2,"TEMPERATURE");
  while(1){
 if(sw1==0) {
     Lcd_Custom_Cmd(Lcd_Clear);
       address =0;
      d1a=Eeprom_Read(address);
      address =1;
      d2a=Eeprom_Read(address);
      address =2;
      d3a=Eeprom_Read(address);

  DELAY_MS(1000);

 address =3;
      d1b=Eeprom_Read(address);
      address =4;
      d2b=Eeprom_Read(address);
      address =5;
      d3b=Eeprom_Read(address);

 address =6;
      d1c=Eeprom_Read(address);
      address =7;
      d2c=Eeprom_Read(address);
      address =8;
      d3c=Eeprom_Read(address);

    Lcd_Custom_Chr(1,2,48+d1a);
    Lcd_Custom_Chr(1,3,48+d2a);
    Lcd_Custom_Chr(1,4,48+d3a);

    Lcd_Custom_Chr(1,10,48+d1b);
    Lcd_Custom_Chr(1,11,48+d2b);
    Lcd_Custom_Chr(1,12,48+d3b);

    Lcd_Custom_Chr(2,2,48+d1c);
    Lcd_Custom_Chr(2,3,48+d2c);
    Lcd_Custom_Chr(2,4,48+d3c);
      DELAY_MS(3000);
    while(sw1==0);
     Lcd_Custom_Cmd(Lcd_Clear);
  DELAY_MS(1000);



}//get_ad();
 get_hb();
//  Lcd_Custom_Cmd(Lcd_Clear);
  DELAY_MS(2000);

 disp_hb();
   DELAY_MS(2000);
// disp_hb();



                 }
         }
//==================================================

void disp_hb() {
 cnt=cnt*6;
     tlong=cnt;
      Lcd_Custom_Chr(1,1,'h');
    LCD_Custom_Chr_CP('b');
    LCD_Custom_Chr_CP('=');
    ch     = tlong / 1000;                 // extract volts digit
     Lcd_Custom_Chr(1,4,48+ch);

    ch    = (tlong / 100) % 10;            // extract 0.1 volts digit
    d1=ch;

     LCD_Custom_Chr_CP(48+ch);

    ch    = (tlong / 10) % 10;             // extract 0.01 volts digit
   d2=ch;
     LCD_Custom_Chr_CP(48+ch);
    ch    = tlong  % 10;             // extract 0.01 volts digit
   d3=ch;
     LCD_Custom_Chr_CP(48+ch);

cnt2++;
if(cnt2>3)cnt2=1;

if(cnt2==1){
          Eeprom_Write(0,d1 );
          Eeprom_Write(1,d2 );
          Eeprom_Write(2, d3);

}
if(cnt2==2){
          Eeprom_Write(3,d1 );
          Eeprom_Write(4,d2 );
          Eeprom_Write(5, d3);

}
if(cnt2==3){
          Eeprom_Write(6,d1 );
          Eeprom_Write(7,d2 );
          Eeprom_Write(8, d3);

}

}

void disp_hb2() { /////with out multiply
// cnt=cnt*6;
     tlong=cnt;
      Lcd_Custom_Chr(2,1,'h');
    LCD_Custom_Chr_CP('b');
    LCD_Custom_Chr_CP('=');
    ch     = tlong / 1000;                 // extract volts digit
     Lcd_Custom_Chr(2,4,48+ch);

    ch    = (tlong / 100) % 10;            // extract 0.1 volts digit

     LCD_Custom_Chr_CP(48+ch);

    ch    = (tlong / 10) % 10;             // extract 0.01 volts digit
     LCD_Custom_Chr_CP(48+ch);
    ch    = tlong  % 10;             // extract 0.01 volts digit
     LCD_Custom_Chr_CP(48+ch);



}


 void  get_hb() {
unsigned char  i=0,j=0;
 cnt=0;
   Lcd_Custom_Out(3,1,"                     ");
    Lcd_Custom_Chr(3,1,'>');
 for(j=0;j<30;j++) {
  delay_ms(100);
  disp_hb2();
 if(hbit==0) {
 cnt++;
while(hbit==0);
}



                    }



//
 }

  void  get_ad()
{

      adc_rd0  = ADC_read(0);
        Delay_ms(500);

    tlong = (long)adc_rd0 * 5000;
    tlong = tlong / 1023;

    ch     = tlong / 1000;                 // extract volts digit
    Lcd_Custom_Chr(1,10,48+ch);

    ch    = (tlong / 100) % 10;            // extract 0.1 volts digit
     LCD_Custom_Chr_CP(48+ch);
    ch    = (tlong / 10) % 10;             // extract 0.01 volts digit
     LCD_Custom_Chr_CP(48+ch);

        Delay_ms(500);
    LCD_Custom_Chr_CP('c');





}
I CANNOT FIND ERROR IN MY PROGRAM PLZ HELP ME IN
FINDING IT
 

i am getting error like
"30 324 Undeclared identifier 'Lcd_Custom_Config' in expression n2.c",
"31 324 Undeclared identifier 'Lcd_Custom_Cmd' in expression n2.c"
 

You are using mikroC Pro compiler but mikroC code. Please check the help file LCD library section on how to use LCD functions and LCD defines. If you explain what exactly you want to do then a better and smaller code can be written.
 
hello,

Code:
 Lcd_Custom_Config(&PORTB,7,6,5,4,&PORTB,2,0,3);

Are you using an external library to define LCd_Custom_config ?
copy/paste the result of compiling from "Messages" window



it is better to use
in OPTIONS
Output Settings
Case sensitive (actived)

it needs more pay attention, but more easy to debug..
and the Syntaxe becomes exactly the same as in library description or help fromMikroE
Same for indentation..
A good identattion in your code , will render a better understanding of your program..

- - - Updated - - -

hello,

Code:
 Lcd_Custom_Config(&PORTB,7,6,5,4,&PORTB,2,0,3);

Are you using an external library to define LCd_Custom_config ?
copy/paste the result of compiling from "Messages" window



it is better to use
in OPTIONS
Output Settings
Case sensitive (actived)

it needs more pay attention, but more easy to debug..
and the Syntaxe becomes exactly the same as in library description or help fromMikroE
Same for indentation..
A good identattion in your code , will render a better understanding of your program..


What is your version of MikroC PRO ?
With MikroC PRO 6.40 you can use "LCD" library !

nota: i don't find anymore "LCD_CUSTOM" in the libraries list !

see help for LCD , and change the Hardware init as you want

Code:
[I] Lcd pinout settings[/I]
[B]sbit[/B] LCD_RS [B]at[/B] RB4_bit;
[B]sbit[/B] LCD_EN [B]at[/B] RB5_bit;
[B]sbit[/B] LCD_D7 [B]at[/B] RB3_bit;
[B]sbit[/B] LCD_D6 [B]at[/B] RB2_bit;
[B]sbit[/B] LCD_D5 [B]at[/B] RB1_bit;
[B]sbit[/B] LCD_D4 [B]at[/B] RB0_bit;

[I]// Pin direction[/I]
[B]sbit[/B] LCD_RS_Direction [B]at[/B] TRISB4_bit;
[B]sbit[/B] LCD_EN_Direction [B]at[/B] TRISB5_bit;
[B]sbit[/B] LCD_D7_Direction [B]at[/B] TRISB3_bit;
[B]sbit[/B] LCD_D6_Direction [B]at[/B] TRISB2_bit;
[B]sbit[/B] LCD_D5_Direction [B]at[/B] TRISB1_bit;
[B]sbit[/B] LCD_D4_Direction [B]at[/B] TRISB0_bit;
...

Lcd_Init();
 
Last edited:
thanks to all i found error it was in in"Lcd_Custom_Config(&PORTB,7,6,5,4,&PORTB,2,0,3)" i removed _custom from the program and it worked
 

now i want to add buzzer program such that buzzer is connected to 0 pin of port b .so can anyone help me regarding this
 

hello,

Does your program must do anything else,when you do the Buzz ?
if you need to Buzz and do another task, you need to use interrupt..
you can arm a timer with a short time
ex: 1000 hz 1mS => timer with 500µS ,
inside interrupt of timer, toggle the bit RB0
You need also a conditional flag to Arm or disarm this timer ..

or if you enter in an infinite conditional loop
you simply can use Delay_ms or Delay_uS function

Code:
while (Mycondition==1)
{
 PORTB.RB0=1;
 Delay_us(500);
 PORTB.RB0=0;
Delay_us(500);
}
 

what is your FOSC ?
quartz value ?


Can you use RB0 or RA4 as input for counting pulses ?
 

hello,


I fund some error in conversion number to asccii LCD.. unit was missing
example value 0295 showed 029... now it is correct to show value up to 9999
added extra variables to store 4 digits value in Eeeprom d1 to d4 instead of d1 to d3
use of timer0 as counter for pulses.
use of timer1, in interrupt mode to generate 10 second event
so at each 10second event, read the Tmr0 and multiply by 6 => nb of heart beat / minuye
And also, after 6 events => 6x10 sec , show the cumul of pulse during 60 seconds => more accurate !
Nb heart beats / minute.
I used RS232 output instead LCD , because no LCD available.. and Q=20Mhz soldered on my IrdABoard card.

active the #define Used_LCD and #define Q4Mhz
or remove all UARTxxx parts.



Result with 4.88Hz on RA4 input
the value 1023 is an analog value on RA0
4.88*10*6= 292.8 => 292 or 293

19:09:20.031>
19:09:20.031> RIPAH INTERNATIONAL
19:09:20.031> 1023
19:09:30.031> 294
19:09:30.093> 1023
19:09:40.031> 294
19:09:40.093> 1023
19:09:50.031> Mn:0146
19:09:50.031> 1023
19:10:00.031> 294
19:10:00.093> 1023
19:10:10.031> 294
19:10:10.093> 1023
19:10:20.031> 294
19:10:20.093> 1023
19:10:30.031> 294
19:10:30.093> 1023
19:10:40.031> 294
19:10:40.093> 1023
19:10:50.031> Mn:0293
19:10:50.031> 1023
19:11:00.031> 294
19:11:00.093> 1023
19:11:10.031> 294
*/



Code:
 // 13/9/2014
 // tested on my IrdA board Microchip with LCD , but LCD not wired at same pins
 // CONFIG : $2007 : 0x3B3A
 
 
//#define LCD_Used
// #define  Q4Mhz

#define CLS 12
#define CR 13
#define LF 10
#define BS 8
#define TAB 9

//#define  hbit    PORTB.F0
//#define  sw1    PORTD.F0


volatile unsigned int count1;  // count nb of 250mS
volatile unsigned int Flag_10sec;
volatile unsigned int Flag_Minute;
volatile unsigned int  Cumul_Cnt,count0;

#define NbIT_for_10sec   99   // 100*100mS => 10 sec


unsigned char CRam1[32];
unsigned int adc_rd0;
unsigned char ch;
char TEXTE[32];
char *txt;
int i,j;
unsigned long tlong;
unsigned char  cnt=0,indh=0,ind=0,cnt2=0;
unsigned int address;
unsigned char d1a,d2a,d3a;d4a;   // d4x added for diplay unit
unsigned char d1b,d2b,d3b,d4b;
unsigned char d1c,d2c,d3c,d4c;
unsigned char d0; // <- add this if display up to 99999
unsigned char d1,d2,d3,d4; // to display up to 9999


#ifdef LCD_Used
//sbit LCD_D4 at RB4_bit;
sbit LCD_D5 at RB5_bit;
sbit LCD_D6 at RB6_bit;
sbit LCD_D7 at RB7_bit;
sbit LCD_EN at RB3_bit;
sbit LCD_RS at RB2_bit;
sbit LCD_RS_Direction at TRISB2_bit;
sbit LCD_EN_Direction at TRISB3_bit;
sbit LCD_D4_Direction at TRISB4_bit;
sbit LCD_D5_Direction at TRISB5_bit;
sbit LCD_D6_Direction at TRISB6_bit;
sbit LCD_D7_Direction at TRISB7_bit;
#endif


sbit hbit at RB0_bit;

//sbit sw1 at RD0_bit;

 // specifi to this IRDaBoard !
sbit sw1 at RA5_bit ;       // Switch2 avec rappel au +5V
//#define SW3 PORTA.RA4      // Switch1 avec rappel au +5V
sbit Reset_MCP2150 at RC0_bit ;
sbit LCD_PWR       at RD5_bit ;    // to power on the LCD
#define   Led_Verte_D0 RD0_bit
#define   Led_Verte_D1 RD1_bit
#define   Led_Verte_D2 RD2_bit
#define   Led_Verte_D3 RD3_bit
#define   Led_Verte_D4 RD4_bit
#define   Led_Verte_D5 RD5_bit
#define   Led_Verte_D6 RD6_bit
#define   Led_Verte_D7 RD7_bit


void  get_ad(void);
void  get_hb(void);
void  disp_hb1(void);
void  disp_hb2(void)  ;
#ifndef LCD_used
void UART1_Write_CText(const char *txt)  ;
void CRLF(void);
#endif
void Init_Timer1(void);
void Init_Timer0_as_counter(void);


 void Interrupt() iv 0x0004 ics ICS_AUTO
 {
   // -- Timer1 --------------
    if ((TMR1IE_bit)&&(TMR1IF_bit))
      {

      #ifdef Q4Mhz
       TMR1L=  0x2B;
       TMR1H=  0xCF; // 53035  init à 100mS at 4Mhz
      #else
       TMR1L=  0xDB;
       TMR1H=  0x0B; // 3035  init à 100mS at 20Mhz
       #endif
       Led_Verte_D0=!Led_Verte_D0 ;
       count1++;                  //Increase counter by one

      if (count1 >NbIT_for_10sec)
        {
         cnt=TMR0;
         Cumul_Cnt=Cumul_Cnt+cnt;
         Flag_10sec=1;
         TMR0=0;
         count1=0;
         Flag_Minute++;
         Led_Verte_D1=1;
         }
      TMR1IF_bit = 0;
      }

 }




 void Init_Timer0_as_counter(void)
 {
   OPTION_REG=0;
   OPTION_REG.T0CS=1;  // Counter mode ,transistion on T0CKI pin RA4
   OPTION_REG.PSA=1; // Prescaler NOT used
    OPTION_REG.T0SE=1;  //0 = Increment on low-to-high transition on T0CKI pin
   T0IF_bit=0;
   PS2_bit=0;
   PS1_bit=0;
   PS0_bit=0; // 1:2
   TMR0IF_bit=0;
   TMR0IE_bit=0; 
   TMR0=0;
 }

void Init_Timer1(void)
 {
  T1CON=0;
 // T1CON=0b00110000;
  TMR1CS_bit=0;   // FOSC /4 internal clock .. page 52
  T1CKPS1_bit=1;  //prescal select=11 => 1/8
  T1CKPS0_bit=1;
  TMR1H= 0x0B; // Hi (3035);  // init à 250mS at 8Mhz   62500*8*cycle duration
  TMR1L= 0xDB; // Lo (3035);
  PIR1.TMR1IF=0;     // Reset Timer1 Flag
  PIE1.TMR1IE=0;  //Enable interrupt TMR1
  TMR1ON_bit=0;
}


void UART1_Write_CText(const char *txt)
 {
   while (*txt)
      UART1_Write(*txt++);
}

void CRLF()
 { UART1_Write(10);
  UART1_Write(13);
  }

void disp_hb1()
{

    tlong=cnt * 6;
#ifdef LCD_Used
    Lcd_Chr(1,1,'h');
    LCD_Chr_CP('b');
    LCD_Chr_CP('=');
  //  ch     = (tlong / 1000)%10;                 // extract volts digit
  //  d0=ch;
  //  Lcd_Chr(1,4,48+ch);
    ch    = (tlong / 1000) % 10;            // extract 0.1 volts digit
    d1=ch;
    Lcd_Chr(1,5,48+ch);
    ch    = (tlong / 100) % 10;             // extract 0.01 volts digit
    d2=ch;
    LCD_Chr_CP(48+ch);
    ch    = (tlong /10)  % 10;             // extract 0.01 volts digit
    d3=ch;
     LCD_Chr_CP(48+ch);
    ch    = tlong  % 10;             // extract 0.01 volts digit
    d4=ch;
     LCD_Chr_CP(48+ch);
#else
       LongWordToStr(tlong, txt);
       UART1_Write_Text(txt);
       CRLF();
       d0= (tlong / 10000)%10 ;
       d1= (tlong / 1000)%10;
       d2= (tlong / 100)%10;
       d3= (tlong / 10)%10;
       d4=  tlong %10;
       
#endif

     // to store value of 4 digit so maxi could be 9999
     cnt2++;
     if(cnt2>3)cnt2=1;
     if(cnt2==1){
          EEPROM_Write(0,d1 );  Delay_ms(10);
          EEPROM_Write(1,d2 ); Delay_ms(10);
          EEPROM_Write(2, d3); Delay_ms(10);
          EEPROM_Write(3, d4); Delay_ms(10);

     }
     if(cnt2==2){
          EEPROM_Write(4,d1 ); Delay_ms(10);
          EEPROM_Write(5,d2 ); Delay_ms(10);
          EEPROM_Write(6, d3);  Delay_ms(10);
          EEPROM_Write(7, d4);  Delay_ms(10);

          }
     if(cnt2==3){
          EEPROM_Write(8,d1 ); Delay_ms(10);
          EEPROM_Write(9,d2 ); Delay_ms(10);
          EEPROM_Write(10, d3); Delay_ms(10);
          EEPROM_Write(11, d4); Delay_ms(10);
          }
      Flag_10sec=0;
      Led_Verte_D1=0;
}

void disp_hb2() 
{ // during One minute
   tlong=Cumul_Cnt;
   // d0= (tlong / 10000)%10;   // use it , if tlong > 9999
   d1= (tlong / 1000)%10;
   d2= (tlong / 100)%10;
   d3= (tlong / 10)%10;
   d4=  tlong % 10 ;
   #ifdef LCD_Used
   Lcd_Chr(2,1,'h');
   LCD_Chr_CP('b');
   LCD_Chr_CP('=');
   Lcd_Chr(2,4,48+d1);
   LCD_Chr_CP(48+d2);
   LCD_Chr_CP(48+d3);
   LCD_Chr_CP(48+d4);
   #else
     UART1_Write('M');  UART1_Write('n');UART1_Write(':');
     UART1_Write(d1+48);
     UART1_Write(d2+48);
     UART1_Write(d3+48);
     UART1_Write(d4+48);
     CRLF();
     /* or another wait using libray
    txt=TEXTE;
    LongWordToStr(Cumul_Cnt, txt);
    UART1_Write_Text(txt);
    CRLF();
    */
   #endif
   Cumul_Cnt=0;
   cnt=0;
   Flag_10sec=0;
   Flag_Minute=0;
}


void  get_hb()
{
// we enter here ,just afer Timer1 interrupt
 #ifdef LCD_Used
 Lcd_Out(3,1,"                     ");
 Lcd_Chr(3,1,'>');
 #endif
 Flag_10sec=0;
 if (Flag_Minute>5)
 { 

  Led_Verte_D7=1 ;
  disp_hb2();
  Flag_Minute=0;
  Led_Verte_D7=0  ;
 }
 else
  {
   disp_hb1();
  }
}




void main()   {

Delay_ms(500);
TRISA=0b11111111;   // if RA4 used as input
ADCON1=0b10001110;
ADCON0 = 0b01000000;     // FOSC/8 ch0
TRISB  = 0b00000001; //if  RB0 used as input
TRISC  = 0xFF;
PORTC.RC6=0;
PORTC.RC7=1;
TRISD=0b00000000 ;
PORTD=0;
txt=TEXTE;

 Led_Verte_D7=1;
 Reset_MCP2150=0;   // reset MCP2150  specific to this IRDAboard !
 LCD_PWR =0;       //   specific to this IRDAboard , don't power LCD!
 Delay_ms(100);

 // LCD not used here, because can not change hardware LCD wiring  ,soldered !
 #ifdef LCD_Used
 Lcd_Init();
 Delay_ms(500);
 Lcd_Cmd(_Lcd_CURSOR_OFF);
 Lcd_Cmd(_Lcd_Clear);
 #else
  UART1_Init(19200);
 Delay_ms(100);
  UART1_Write(CLS); // erase display on terminal VBRAY
  Delay_ms(500);
  CRLF();
 #endif
 Led_Verte_D7=0;   //   specific to this IRDAboard
 ADCON0 = 0x81;
  //ADCON1     = 0x82;                       // configure VDD as Vref, and analog channels
  Init_Timer0_as_counter() ;

  #ifdef LCD_Used
  Lcd_Out(1,2,"RIPAH INTERNATIONAL ");
  Delay_ms(1000);
  Lcd_Cmd(_Lcd_Clear);
  #else
  UART1_Write_CText( "RIPAH INTERNATIONAL \r\n");
  #endif
  
   address =0;
      d1a=EEPROM_Read(address);
      address =1;
      d2a=EEPROM_Read(address);
      address =2;
      d3a=EEPROM_Read(address);
      address =3;
      d4a=EEPROM_Read(address);
      address =4;
      d1b=EEPROM_Read(address);
      address =5;
      d2b=EEPROM_Read(address);
      address =6;
      d3b=EEPROM_Read(address);
      address =7;
      d4b=EEPROM_Read(address);
      address =8;
      d1c=EEPROM_Read(address);
      address =9;
      d2c=EEPROM_Read(address);
      address =10;
      d3c=EEPROM_Read(address);
      address =11;
      d4c=EEPROM_Read(address);
 //  Lcd_Custom_Out(2,2,"TEMPERATURE");
 
  Init_Timer1(); // interrupt every 250mS at 8MHz

  PIR1.TMR1IF=0;     // Reset Timer1 Flag
  PIE1.TMR1IE=1;  //Enable interrupt TMR1
  INTCON.PEIE=1;
  GIE_bit=1;
  Flag_10sec=0;
  count1=0;
  count0=0;
  Cumul_Cnt=0;
  cnt=0;
  TMR0=0;
  T1CON.TMR1ON=1; // Start the counter

 
 while(1)
 {
   adc_rd0= ADC_Read(0);      // result is the average on 32 meaures
   WordToStr(adc_rd0,CRam1);
   UART1_Write_Text(CRam1);
   CRLF();

   if(sw1==0)
   {  UART1_Write('S');UART1_Write('W');UART1_Write('1');UART1_Write(TAB);
      #ifdef LCD_Used
      Lcd_Cmd(_Lcd_Clear);
      #endif
      address =0;
      d1a=EEPROM_Read(address);
      address =1;
      d2a=EEPROM_Read(address);
      address =2;
      d3a=EEPROM_Read(address);
      address =3;
      d4a=EEPROM_Read(address);
  //    Delay_ms(100);
      address =4;
      d1b=EEPROM_Read(address);
      address =5;
      d2b=EEPROM_Read(address);
      address =6;
      d3b=EEPROM_Read(address);
      address =7;
      d4b=EEPROM_Read(address);
      address =8;
      d1c=EEPROM_Read(address);
      address =9;
      d2c=EEPROM_Read(address);
      address =10;
      d3c=EEPROM_Read(address);
      address =11;
      d4c=EEPROM_Read(address);
      
      
    #ifdef LCD_Used
    Lcd_Chr(1,2,48+d1a);
    Lcd_Chr(1,3,48+d2a);
    Lcd_Chr(1,4,48+d3a);
    Lcd_Chr(1,5,48+d4a);
    
    Lcd_Chr(1,10,48+d1b);
    Lcd_Chr(1,11,48+d2b);
    Lcd_Chr(1,12,48+d3b);
    Lcd_Chr(1,13,48+d4b);
    
    Lcd_Chr(2,2,48+d1c);
    Lcd_Chr(2,3,48+d2c);
    Lcd_Chr(2,4,48+d3c);
    Lcd_Chr(2,5,48+d4c);
    Delay_ms(1000);
    #else
     UART1_Write( 48+d1a);
      UART1_Write( 48+d2a);
       UART1_Write( 48+d3a);
        UART1_Write( 48+d4a);
         UART1_Write( 48+d1b);
          UART1_Write( 48+d2b);
           UART1_Write( 48+d3b);
            UART1_Write( 48+d4b);
             UART1_Write( 48+d1c);
              UART1_Write( 48+d2c);
               UART1_Write( 48+d3c);
                UART1_Write( 48+d4c);
               
       CRLF();
    #endif
    while(sw1==0);
    #ifdef LCD_Used
     Lcd_Cmd(_Lcd_Clear);
     #endif
    // Delay_ms(1000);
   }  // if sw1...
  while(Flag_10sec==0) ; // wait timer1 elapsed
  get_hb();
 }; // while(1)
}
 

Use array to store the values which you send to eeprom.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top