CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

this is the lcd display program

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
madhunica



Joined: 22 Dec 2013
Posts: 6

View user's profile Send private message

this is the lcd display program
PostPosted: Mon Mar 17, 2014 6:10 am     Reply with quote

i have no error & warnings.... but the simulation is not come... can you help me ?

Code:
#include <16F877A.h>
#DEVICE ADC=10
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
#use delay(clock=12000000)
#use rs232(baud=9600,xmit=PIN_C6,rcv=PIN_C7,TIMEOUT=5000)


//#include <flex_lcd.c>
#fuses hs, nowdt, nolvp, noprotect   //Config
#use delay (clock = 12000000)      //12MHz Crystal



//#define T0_INTS_PER_SEC76    // (20,000,000/(4*256*256))
#define T1_INTS_PER_SEC 46    // (12,000,000/(4*1*65536))
 
byte int_count1;   
#define lcd_port output_d
void Timer1_ISR(void);
void init(void);      //Function Prototype
void busy_test(void);
void display(void);

void send_command(void);
void send_data(void);
//void putdat_lcd(int data);
unsigned char PORTE, TRISE, PORTD, TRISD, RS, RW, E, BF;
unsigned char command, data;

char voltage[8];
char current[8];
char time[8];

unsigned int16 value=0;
int i, sec,dval,dval2=0;


//
//#DEVICE ADC=10;
#byte PORTE = 0x07
#byte TRISE = 0x87
#byte PORTD = 0x08
#byte TRISD = 0x88

#bit RS = PORTE.0
#bit RW = PORTE.1
#bit E  = PORTE.2
#bit BF = PORTD.7

#INT_TIMER1
void Timer1_ISR(void)
{
//setup_timer_1(T1_DISABLED);
if(--int_count1==0)
{
sec++;
int_count1=T1_INTS_PER_SEC;
}
//setup_timer_1(T1_INTERNAL|T1_DIV_BY_8);
//output_(0x00);
//Set_Timer1(1000);
//TMR1L:=0x18;
}

void displayVoltage(int adc) {
  char voltage[9];
   sprintf(voltage, "%f", (float)adc * .01960784); // Converts adc to text
   voltage[4] = '\0';                              // Limit shown digits to 3
  // glcd_rect(45, 18, 69, 25, YES, OFF);            // Clear the old voltage
//   glcd_text57(45, 18, voltage, 1, ON);            // Write the new voltage
}

void main()
{
 
 int_count1=T1_INTS_PER_SEC;
 setup_timer_1(T1_DIV_BY_1|T1_INTERNAL);
 set_timer1(0);
  enable_interrupts(INT_TIMER1);
 //setup_timer_1(T1_INTERNAL|T1_DIV_BY_8);
// ClearBit(TMR1IF);
// TMR1H =0xFC;
// TMR1L:=0x18;
 //SetBit(TMR1IF);
 //INTCON=0xC0;
 
 sec=0;
 //SetBit(TICON);
   enable_interrupts(GLOBAL);
 //set_timer1(1000);
 init();
 
  busy_test();
   command = 0x81;   //Set DDRAM Address To 0x00
   send_command();
  delay_ms (10);

   busy_test();
   data = 'C';//0x50;   //Display "P"
   send_data();
 
   delay_ms (10);
   busy_test();
   data = 'R';//0x50;   //Display "P"
   send_data();
   delay_ms (10);
   busy_test();
   data = 'E';//0x50;   //Display "P"
   send_data();
   
   delay_ms (10);
   busy_test();
   data = 'A';//0x50;   //Display "P"
   send_data();
   
   delay_ms (10);
   busy_test();
   data = 'T';//0x50;   //Display "P"
   send_data();
   
   delay_ms (10);
   busy_test();
   data = 'I';//0x50;   //Display "P"
   send_data();
   
   delay_ms (10);
   busy_test();
   data = 'N';//0x50;   //Display "P"
   send_data();
   
   delay_ms (10);
   busy_test();
   data = 'I';//0x50;   //Display "P"
   send_data();
   
   delay_ms (10);
   busy_test();
   data = 'N';//0x50;   //Display "P"
   send_data();
   
   delay_ms (10);
   busy_test();
   data = 'E';//0x50;   //Display "P"
   send_data();
   
    delay_ms (10);
   busy_test();
   data = ' ';//0x50;   //Display "P"
   send_data();
   
   
   delay_ms (10);
   busy_test();
   data = 'A';//0x50;   //Display "P"
   send_data();
   
   delay_ms (10);
   busy_test();
   data = 'N';//0x50;   //Display "P"
   send_data();
   
   delay_ms (10);
   busy_test();
   data = 'A';//0x50;   //Display "P"
   send_data();
   
   delay_ms (10);
   busy_test();
   data = 'L';//0x50;   //Display "P"
   send_data();
   
   delay_ms (10);
   busy_test();
   data = 'Y';//0x50;   //Display "P"
   send_data();
   
   delay_ms (10);
   busy_test();
   data = 'S';//0x50;   //Display "P"
   send_data();
   
   delay_ms (10);
   busy_test();
   data = 'E';//0x50;   //Display "P"
   send_data();
   
   delay_ms (10);
   busy_test();
   data = 'R';//0x50;   //Display "P"
   send_data();
strt:
   display();
   
//  sec++;
// display_2();
 goto strt;

 // if (getc()== 'A')
//{
//first==getc();
  delay_ms (100);
 //goto strt;
   //while (1)
  // {

  // } 
}
void init()
{
   set_tris_c(0x00);
   set_tris_e(0x00);   //Set Port C As Output
   set_tris_d(0x00);   //Set Port D As Output
   output_e(0x00);   //Clear Port C
   output_c(0x00);
   output_d(0x00);   //Clear Port D
   delay_ms (500);   //Power-On Delay
         //Busy Flag Valid Here

   //busy_test();   //Check Busy Flag
  // command = 0x38;   //8-Bits, 2-Lines, 5x7 Dots
  // send_command();   //Send Command To LCD

   delay_ms (10);

   //busy_test();   //Check Busy Flag
   command = 0x38;   //8-Bits, 2-Lines, 5x7 Dots
   send_command();   //Send Command To LCD

  // delay_us (500);
  //busy_test();   //Check Busy Flag
   command = 0x38;   //8-Bits, 2-Lines, 5x7 Dots
   send_command();   //Send Command To LCD

   delay_ms (100);

   busy_test();   //Check Busy Flag
   command = 0x06;   //8-Bits, 2-Lines, 5x7 Dots
   send_command();   //Send Command To LCD

   delay_ms (1);

   busy_test();   //Check BF
   command = 0x0c;   //Display Off, Cursor Off, No-Blink
   send_command();   //Send

   delay_ms (1);

   busy_test();
   command = 0x01;   //Clear Display
   send_command();

   delay_ms (5);

   busy_test();
   command = 0x02;   //Increment Cursor Position, No-Shift
   send_command();

 //  delay_ms (1);

//   busy_test();
  // command = 0x0F;   //Display On, Cursor On, Blink
 //  send_command();

 

   delay_ms (10);
}


void display()
{

  setup_adc(ADC_CLOCK_INTERNAL);
   setup_adc_ports(ALL_ANALOG); 
   set_adc_channel(0);
   
   for(i=1;i<6;i++)
   {
   value=read_adc();
   
   delay_us(10); 
   }
 // Dcv = value* (5000/1024.0);
   dval=value;
   value = value * 49;
 // lcd_gotoxy(1,2);
 for(i=1;i<=7;i++)
 {
   voltage[i]=value%10;
   value=value/10;
  }
 
 // setup_adc(ADC_CLOCK_INTERNAL);
 //  setup_adc_ports(ALL_ANALOG); 
   set_adc_channel(1);
   
   for(i=1;i<6;i++)
   {
   value=read_adc();
   delay_us(10); 
   }
 // Dcv = value* (5000/1024.0);
   dval2=value;
   value = value * 49;
 // lcd_gotoxy(1,2);
 for(i=1;i<=7;i++)
 {
   current[i]=value%10;
   value=value/10;
  }
 
   value = sec;
 //  value = value ;
 // lcd_gotoxy(1,2);
 for(i=1;i<=7;i++)
 {
   time[i]=value%10;
   value=value/10;
  }
 
 
   busy_test();
   command = 0xc0;   //Set DDRAM Address To 0x00
   send_command();
     //Adval = (ADRESH * 256) + ADRESL;

   delay_ms(100);
  // putdat_lcd(j);
 // sprintf(line,"%02LX",j);
   
   
  // busy_test();
  // command = 0xd9;   //Set DDRAM Address To 0x00
  // send_command();

   delay_ms (10);

   busy_test();
   data = 'V';//0x50;   //Display "P"
   send_data();
   busy_test();
   data = (':');//0x50;   //Display "A"
   send_data();
  //  busy_test();
  // data = (voltage[7]+0x30);//0x50;   //Display "S"
  // send_data();
    busy_test();
   data = (voltage[6]+0x30);//0x50;   //Display "S"
   send_data();
    busy_test();
   data = (voltage[5]+0x30);//0x50;   //Display "S"
   send_data();
   busy_test();
   data = (voltage[4]+0x30);//0x50;   //Display "S"
   send_data();
   busy_test();
   data = (voltage[3]+0x30);//0x50;   //Display "S"
   send_data();
  // busy_test();
 //  data = ('.');//0x4C;   //Display "S"
 //  send_data();
   busy_test();
   data = (voltage[2]+0x30);//0x50;   //Display "S"
   send_data();
    busy_test();
   data = ('.');//0x4C;   //Display "S"
   send_data();
   busy_test();
   data = (voltage[1]+0x30);//0x50;   //Display "S"
   send_data();
   delay_ms (10);

void busy_test()
{
   
      set_tris_d(0xFF);      //Set Port D As Input
      //RS = 0;            //Command
      //RW = 1;            //Read Busy Flag
      output_e(0x02);
      delay_ms(1);
     // delay_cycles (2);   //Control Setup Time
      //E  = 1;            //E-Line High
      output_e(0x06);
      delay_ms(1);
     // delay_cycles (6);   //Wait Data Return
        // delay_us(
      //if (BF == 0)
      while ( input(PIN_D7));
         set_tris_d(0x00);   //Set Port D Back To Output
         //E  = 0;         //E-Line Low
         output_e(0x02);
       

      //E  = 0;            //E-Line Low
     // output_e(0x02);
       //End while loop
}      //End Function


void send_command()

   output_d(command); 
   //RS = 0;            //Command
   //RW = 0;            //Write Instruction
   output_e(0x00);
   delay_ms(1);
//   delay_cycles (2);   //Control Setup Time
   //E  = 1;            //E-Line High
   output_e(0x04);
    delay_ms(1);
   //delay_cycles (3); 
  // PORTD = command;   //Put Command To Port D
    delay_ms(1);
    // delay_cycles (3);   //Data Setup Time
   //E  = 0;            //E-Line Low
   output_e(0x00);
   delay_ms(1);
   //delay_cycles (1);   //Control & Data Hold Time
}

void putdat_lcd(int data)
{
  lcd_port(data);
  output_high(RS);
  output_high(E);
  delay_ms(1);
  output_low(E);
  delay_ms(6);
  output_low(RS);
}

 
 
void send_data()
{
   output_d(data);
  //RS = 1;            //Data
   //RW = 0;            //Write data
   output_e(0x01);
   delay_ms(1);
   //delay_cycles (2);   //Control Setup Time
   //E  = 1;            //E-Line High
   output_e(0x05);
   delay_ms(1);
   //delay_cycles (3);
  // PORTD = data;      //Put Data To Port D

  // delay_cycles (3);   //Data Setup Time
   //E  = 0;            //E-Line Low
   output_e(0x01);
   delay_ms(1);
   //delay_cycles (1);   //Control & Data Hold Time
}
temtronic



Joined: 01 Jul 2010
Posts: 9246
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Mon Mar 17, 2014 7:19 am     Reply with quote

comments.
1) nobody here can fix PROTEUS problems...so build real hardware.You should use a current PIC, the 877 is almost 20 years old, there are cheaper, better PICs to use.

2) start SMALL ! About 95% of your program is commented out or NOT required so get rid of everything that is not necessary,really start over.

3) I can't follow what you've done..it's way to 'complicated' a 'mixture' of code segments ,none will really work as a 'program'.

Get a PIC and cut the simple '1Hz flashing LED' program. CONFIRM that it works in real hardware.
Do NOT proceed until it does work !

THEN

cut code for the 'test LCD Hello World' program. CONFIRM that it does work in real hardware. I suggest using the 'flex_LCD driver' as it is KNOWN to work very well.

THEN

proceed with your school project.


hth
jay
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group