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.

[SOLVED] LCD working on proteus, but not on hardware, using 16f1507

Status
Not open for further replies.

1230

Member level 3
Joined
Jun 18, 2002
Messages
62
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
355
hello all,


i am using this code for testing LCD, but its only working on proteus, but not on hardware.
i have connected a LED to check whether IC is working or not- IC is working fine.

cannot find out the problem,pls help me.



Code:
// PIC16F1507 Configuration Bit Settings

// 'C' source line config statements

#define _XTAL_FREQ 16000000UL
#include <xc.h>
#include <pic.h>
#include <htc.h>
#include <stdio.h>
//#include <stdlib.h>
//#include <ctype.h>




// CONFIG1

#pragma config FOSC = INTOSC    // Oscillator Selection bits (Internal Oscillator, I/O Function on OSC1)
#pragma config WDTE = OFF       // Watchdog Timer Enable (WDT disabled)
#pragma config PWRTE = OFF      // Power-up Timer Enable (PWRT disabled)
#pragma config MCLRE = OFF      // MCLR Pin Function Select (MCLR/VPP pin function is digital input)
#pragma config CP = ON          // Flash Program Memory Code Protection (Program memory code protection is enabled)
#pragma config BOREN = OFF      // Brown-out Reset Enable (Brown-out Reset disabled)
#pragma config CLKOUTEN = OFF   // Clock Out Enable (CLKOUT function is disabled. I/O or oscillator function on the CLKOUT pin)

// CONFIG2

#pragma config WRT = OFF        // Flash Memory Self-Write Protection (Write protection off)
#pragma config STVREN = OFF      // Stack Overflow/Underflow Reset Enable (Stack Overflow or Underflow will cause a Reset)
#pragma config BORV = LO        // Brown-out Reset Voltage Selection (Brown-out Reset Voltage (Vbor), low trip point selected.)
#pragma config LPBOR = OFF      // Low-Power Brown Out Reset (Low-Power BOR is disabled)
#pragma config LVP = OFF        // Low-Voltage Programming Enable (High-voltage on MCLR/VPP must be used for programming)

//LCD Pins
#define RS 	    0
#define RW 		2
#define EN		1

#define LCD	PORTC


void LCD_NUM(int a);
void LCD_INIT(void);
void LCD_DATA(unsigned char);
void LCD_CMD(char a);


void main()
{
    IRCF0 = 1;
    IRCF1 = 1;
    IRCF2 = 1;
    IRCF3 = 1;
   
    
    TRISB=0x00;
    TRISC=0x00;
    
    LCD_INIT();
   
    int i=0;
    while(1)
    {   
        LCD_NUM(i);
        PORTB=0xff;
        __delay_ms(1000);
        PORTB=0;
        __delay_ms(200);
        if(i==4)
        {
            i=0;
            LCD_CMD(0X01);
        }
        i++;
    }
   
       
     
    
    
}

void LCD_NUM(int a)
 {if(a==0)
   LCD_DATA('0');

  LCD_DATA(0x04);
   int t;
   while(a!=0)
     {
	   t=a%10;
	   a=a/10;
	   LCD_DATA(t+48);
     }
}

void LCD_CMD(char a)
 {
   LCD=a&0b11110000;
   LCD&=~(1<<RS);
   LCD&=~(1<<RW);
   LCD|=(1<<EN);
   __delay_ms(2);
   LCD&=~(1<<EN);
   __delay_ms(2);

   LCD=(a<<4)&0b11110000;
   LCD&=~(1<<RS);
   LCD&=~(1<<RW);
   LCD|=(1<<EN);
   __delay_ms(2);
   LCD&=~(1<<EN);
   __delay_ms(2);
}

void LCD_DATA(char a) 
 {
   LCD=a&0b11110000;
   LCD|=(1<<RS);
   LCD&=~(1<<RW);
   LCD|=(1<<EN);
   __delay_ms(2);
   LCD&=~(1<<EN);
   __delay_ms(2);

   LCD=(a<<4)&0b11110000;
   LCD|=(1<<RS);
   LCD&=~(1<<RW);
   LCD|=(1<<EN);
   __delay_ms(2);
   LCD&=~(1<<EN);
   __delay_ms(2);
}


void LCD_INIT()
 {
   LCD_CMD(0x02);
   LCD_CMD(0x28);
   LCD_CMD(0x06);
   LCD_CMD(0x0c);
}

U ntitled.jpg
 

A 5k potentiometer from +5v to gnd, output to VEE, is for adjusting the contrast of the display, and if incorrectly adjusted can cause the display to be invisible.
 

Thanks for response, but this was not the issue.

Have solved the problem.
need to set ANSELx register.... :)
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top