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.

Proteus CodeVision problem?

Status
Not open for further replies.

Gigica

Newbie level 3
Joined
Aug 22, 2007
Messages
4
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,317
#asm(sei)

Hi, I have a problem with Proteus simulating LCD with c code compiled with CodeVision. Here is schematic and c code .


Code:
/*****************************************************
This program was produced by the
CodeWizardAVR V1.25.3 Professional
Automatic Program Generator
© Copyright 1998-2007 Pavel Haiduc, HP InfoTech s.r.l.
[url]http://www.hpinfotech.com[/url]


Chip type           : AT90S2313
Clock frequency     : 8.000000 MHz
Memory model        : Tiny
External SRAM size  : 0
Data Stack size     : 32
*****************************************************/

#include <90s2313.h>
#include <delay.h> 


void clearDisplay()
{
PORTB=0x08;
#asm("cli")
delay_us(1);
#asm("sei")
PORTB=0;
PORTB=0x18;
#asm("cli")
delay_us(1);
#asm("sei")
PORTB=PORTB&0xf7;
delay_ms(5);
}

void entryModeSet(char inc_dec,char shift_normal)
{PORTB=0x08;
#asm("cli")
delay_us(1);
#asm("sei")
PORTB=0;
PORTB=0x48|(inc_dec<<5)|(shift_normal<<4);
#asm("cli")
delay_us(1);
#asm("sei")
PORTB=PORTB&0xf7;
delay_us(40);
}

void displayOnOff(char display_on,char cursor_on,char blink_on)
{PORTB=0x08;
#asm("cli")
delay_us(1);
#asm("sei")
PORTB=0;
PORTB=0x88|(display_on<<6)|(cursor_on<<5)|(blink_on<<4);
#asm("cli")
delay_us(1);
#asm("sei")
PORTB=PORTB&0xf7;
delay_us(40);
} 

void cursorOrDisplayShift(char displayShift_cursorShift,char right_left)
{PORTB=0x18;
#asm("cli")
delay_us(1);
#asm("sei")
PORTB=PORTB&0xf7;
PORTB=0x08|(displayShift_cursorShift<<7)|(right_left<<6);
#asm("cli")
delay_us(1);
#asm("sei")
PORTB=PORTB&0xf7;
delay_us(40);
}

void functionSet(char data_length,char one_two_rows,char dimension_char)
{PORTB=0x28|(data_length<<4);
#asm("cli")
delay_us(1);
#asm("sei")
PORTB=PORTB&0xf7;
PORTB=0x08|(one_two_rows<<7)|(dimension_char<<6);
#asm("cli")
delay_us(1);
#asm("sei")
PORTB=PORTB&0xf7;
delay_us(40); 
}



void setDDRAMaddress(char address)
{PORTB=(0x88|address)&0xfd;
#asm("cli")
delay_us(1);
#asm("sei")
PORTB=PORTB&0xf7;
PORTB=0x08|(address<<4);
#asm("cli")
delay_us(1);
#asm("sei")
PORTB=PORTB&0xf7;
delay_us(40);
}

void writeData(char data)
{PORTB=0x0a|data;
#asm("cli")
delay_us(1);
#asm("sei")
PORTB=PORTB&0xf7;
PORTB=0x0a|(data<<4);
#asm("cli")
delay_us(1);
#asm("sei")
PORTB=PORTB&0xf7;
delay_us(40);
}

initLCD()
{delay_ms(15);
PORTB=0x38;
#asm("cli")
delay_us(1);
#asm("sei")
PORTB=0;
delay_ms(5);
PORTB=0x38;
#asm("cli")
delay_us(1);
#asm("sei")
PORTB=0;
delay_us(160);
PORTB=0x38;
#asm("cli")
delay_us(1);
#asm("sei")
PORTB=0;
delay_us(160);
PORTB=0x28;
#asm("cli")
delay_us(1);
#asm("sei")
PORTB=0; 
delay_us(160);
//functionSet(0,1,0); 
functionSet(0,1,0); 
delay_ms(1);
displayOnOff(0,0,0);
delay_us(160);
displayOnOff(1,1,0);
delay_us(160);
entryModeSet(1,0);
delay_us(160);

}

void printMessage(flash char*message)
{while(*message)writeData(*message++);}
// Declare your global variables here


                                      
void main(void)
{ 
// Port B initialization
// Func0=Out Func1=Out Func2=Out Func3=Out Func4=Out Func5=Out Func6=Out Func7=Out 
// State0=0 State1=0 State2=0 State3=0 State4=0 State5=0 State6=0 State7=0 
DDRB=0xff;
PORTB=0xff;

// Port D initialization
// Func0=In Func1=In Func2=In Func3=In Func4=In Func5=In Func6=In Func7=In 
// State0=T State1=T State2=T State3=T State4=T State5=T State6=T State7=T
DDRD=0x00; 
PORTD=0x00;

// Timer/Counter 0 initialization
// Clock source: System Clock
// Clock value: 7.813 kHz
TCCR0=0x00;
TCNT0=0x00;

// Timer/Counter 1 initialization
// Clock source: System Clock
// Clock value: Timer 1 Stopped
// Mode: Normal top=FFFFh
// OC1A output: Discon.
// OC1B output: Discon.
// Noise Canceler: Off
// Input Capture on Falling Edge
TCCR1A=0x00;
TCCR1B=0x00;
TCNT1H=0x00;
TCNT1L=0x00;
OCR1AH=0x00;
OCR1AL=0x00;


// External Interrupt(s) initialization
// INT0: Off
// INT1: Off
GIMSK=0x00;
MCUCR=0x00;

// Timer(s)/Counter(s) Interrupt(s) initialization
TIMSK=0x00;


// Analog Comparator initialization
// Analog Comparator: Off
// Analog Comparator Input Capture by Timer/Counter 1: Off
// Analog Comparator Output: Off
ACSR=0x80;
// Global enable interrupts 
initLCD(); 
 
while (1)
{
 clearDisplay();
 printMessage("first row");
 delay_ms(1500);
 setDDRAMaddress(0x40);
 printMessage("second row");
 delay_ms(1500);    
}  
}

I have used AT90S2313 in this example .

The point is that this works in reality (with different AVR-s) but not in Proteus .

link for shematic
51_1229891067.jpg
 

delay_ms codevision example

Proteus is not 100% reliable. I do have similar problem with external interrupt (logic change mode/ATMega16). My code works fine in actual but didn't work on Proteus.
 

problem with data types in codevisionavr

CodeVision has library functions to facilitate the handling of LCD modules built with the Hitachi HD44780 chip or equivalent, why not use it?
 

codewizardavr v1.25.3 professional

Possibly this is a sync issue with 4-bit mode.

As I understand it, when initialising the LCD to be 4-bit mode the LCD is actually in 8-bit mode. This, in turn means that you should not poll for a busy signal here but rather implement a manual delay.

Following that instruction, the LCD state is settled and all writes/ reads should be nibble wide.

I know that most times in hardware an 'incorrect' firmware implementation will work this will be dependant on clock speed.

A 'C' implementation of 4-bit mode can be found in the ../Samples/ directory of the Proteus installation.


Iain.
 

Re: codewizardavr v1.25.3 professional

In the meantime I use lcd.h library included in CodeVision with LCD connections as required and have no problems nither with Proteus simulation nor in reality
 

Normally proteus will work well with lcd's. Im using proteus for long time.

The problem seems to be delays you have given init_lcd routine

Refer the datasheet for proper delays
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top