ATTiny13 + Nokia monochrome lcd

Go To Last Post
20 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello everyone

The problem is that the display from Nokia does not work

controller - PCF8814/STE2007
The screen should be full, but this does not happen.

My code for ATTiny13:

 

#define F_CPU 4000000UL
#include <avr/io.h>
#include <util/delay.h>
#include <avr/pgmspace.h>



#define SCLK_OFF PORTB &= ~(1<<PB0)
#define SCLK_ON PORTB |= (1<<PB0)



#define SDA_OFF PORTB &= ~(1<<PB1)
#define SDA_ON PORTB |= (1<<PB1)



#define CS_OFF PORTB &= ~(1<<PB2)
#define CS_ON PORTB |= (1<<PB2)



#define RST_OFF PORTB &= ~(1<<PB3)
#define RST_ON PORTB |= (1<<PB3)



void send_bits(unsigned char cmd_,unsigned char data){
	

	unsigned char i;
	
	CS_OFF;
	SCLK_OFF;
	
	//send command or data
	if(cmd_){SDA_ON;}
	else{SDA_OFF;}
	
	SCLK_ON;
	
	
	for ( i = 0 ; i < 8 ; i++ )
	{
		SCLK_OFF;
		if ( data & 0x80 )
		{SDA_ON;}
		else
		{ SDA_OFF; }
		
		SCLK_ON;
		data <<= 1;
	}
	
	
	
	
}







void lcd_Init(){
	
	CS_OFF;
	RST_OFF;
	_delay_ms(1);
	RST_ON;
	_delay_ms(50);
	
	send_bits(0,0x20);
	send_bits(0,0xEB);//ON TEMP COMPENSATION
	send_bits(0,0xA4);//NORMAL DISP
	
	send_bits(0,0x2f);//power ctrl on
	send_bits(0,0xc0);//y-mirror
	send_bits(0,0xa6);//non invert normal
	send_bits(0,0xaf);//on display
	send_bits(0,0x90);//max contrast
	
	CS_ON;//off spi
}







void lcd_gotoxy ( unsigned char x , unsigned char y )
{
	CS_OFF;//on spi
	
	send_bits ( 0 , ( 0xB0 | ( y & 0x0F ) ) );
	send_bits ( 0 , ( 0x00 | ( x & 0x0F ) ) );
	send_bits ( 0 , ( 0x10 | ( ( x >> 4 ) & 0x07 ) ) );
	
	CS_ON;//off spi
}









void scr_update(void)
{
	unsigned int i;

	

	lcd_gotoxy(0,0);
	
	CS_OFF;
	
	for( i=0; i<780; i++ ){
		send_bits ( 1 , 0xFF );
	}
	
	
	CS_ON;

}





int main(void)
{
	DDRB |= 1<<PB0;
	DDRB |= 1<<PB1;
	DDRB |= 1<<PB2;
	DDRB |= 1<<PB3;
	
	SCLK_OFF;
	SDA_OFF;
	CS_OFF;
	RST_OFF;
	
	lcd_Init();
	_delay_ms(200);
	scr_update();

	

	while (1)
	{

		
	}

	

}

 

Last Edited: Wed. Jan 15, 2020 - 10:44 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Why, for every bit sent, are you attempting to make 2 clock pulses?  

off

on

off

on

 

SDIN is sampled at the rising edge of SCLK

there are several possible arrangements:

...assume clock is already low, from init:

set data bit hi/lo

clk hi

clk low

repeat   ...finishes with clk low

 

or possibly: 

clk low

set data bit hi/lo

clk hi

repeat    ...finishes with clk hi

 

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

Last Edited: Wed. Jan 15, 2020 - 05:32 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Display connect by 3-line SPI

First bit define command or data

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

You should answer questions with sentences...If you can't bother with a response, why come here?

WHY are you making TWO CLOCK pulses FOR EVERY BIT that you send out? 

Or are you indicating that you do not send out 2 pulses (4 edges) every time?  Please explain.

Every bit must only have ONE clock pulse...that synchronously defines each bit (without clk it's simply a high or low data line & not bits at all).

 

SCLK_OFF;

SCLK_ON;

SCLK_OFF;

SCLK_ON;       

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

Last Edited: Tue. Jan 14, 2020 - 10:28 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

"Dare to be naïve." - Buckminster Fuller

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Does not compile. DATA not defined.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

balisong42 , DATAS is 1

forgot to write

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

reborn99 wrote:
forgot to write
Don't tell me you rewrote all that code into post #1? Surely you just copy/paste the actual code you are building ??

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson I should have written 1 instead of "DATA"
I did not begin to write
#define COMAND 0
#define DATA 1
I replaced macros with numbers, forgetting to replace DАТА with 1

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

This is exactly why you should make sure that your code at least builds before you post it!

 

(unless it's a build error you're asking about)

 

Then use copy & paste - do not manually re-type into the forum.

 

See Tip #1 for how to properly post source code (in my signature, below; may not be visible on mobile).

 

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

awneil  fixed the code in the first post (the code compiles), now it would be nice if someone told me what my error is in the code

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Please do not edit posts after people have commented on them!

 

reborn99 wrote:
now it would be nice if someone told me what my error is in the code

You still haven't answered the question which  avrcandies  has asked you - twice!

In #2, avrcandies wrote:
Why, for every bit sent, are you attempting to make 2 clock pulses?  

Again, in #4, avrcandies wrote:
WHY are you making TWO CLOCK pulses FOR EVERY BIT that you send out? 

 

That certainly seems like an error!

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

awneil I made code based on examples of other libraries, for example:

code from library for the PIC:

void spi(char cd,unsigned char myData)
{
char i;
	cs = 0;
	sclk = 0;
	sda = cd;
	sclk = 1;

for(i=0;i<8;i++){
		sclk = 0;
			if(myData & 0x80)
				sda = 1;
			else
				sda = 0;
		sclk = 1;
		myData <<= 1;
		Delay10TCYx(20);
				}
		cs = 1;
}

My function send_bits(unsigned char cmd_,unsigned char data) is equivalent to this^

 bit of the command \ data (D \ C) is transmitted programmatically via SDA - the first bit

Last Edited: Wed. Jan 15, 2020 - 11:16 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You indentation is all over the place - it makes you code harder to follow.

 

And all that unnecessary whitespace.

 

And please choose just one brace style - and stick to it!

 

void spi(char cd,unsigned char myData)
{
    char i;

    cs = 0;
    sclk = 0;
    sda = cd;
    sclk = 1;

    for(i=0;i<8;i++)
    {
        sclk = 0;

        if(myData & 0x80)
            sda = 1;
        else
            sda = 0;

        sclk = 1;

        myData <<= 1;
        Delay10TCYx(20);
    }

    cs = 1;
}

 

Indeed, the code currently in #1 is now similar:

 

void send_bits(unsigned char cmd_,unsigned char data)
{
    unsigned char i;

    CS_OFF;
    SCLK_OFF;

    //send command or data
    if(cmd_)
    {
        SDA_ON;
    }
    else
    {
        SDA_OFF;
    }

    SCLK_ON;

    for ( i = 0 ; i < 8 ; i++ )
    {
        SCLK_OFF;

        if ( data & 0x80 )
        {
            SDA_ON;
        }
        else
        {
            SDA_OFF;
        }

        SCLK_ON;
        data <<= 1;
    }

}

But is that what you originally posted?

 

 

EDIT

 

One key difference between that spi() function and your send_bits() is that you have no delay - are you sure that's OK?

 

Remember that the timing of PIC code is likely to be different from timing of AVR code - so have you checked that your code meets the LCD's timing requirements ?

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
Last Edited: Wed. Jan 15, 2020 - 11:39 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

awneil

All right, the reason is that I am not transmitting the first bit of the\data command correctly before sending the data (I tried to use 3-lines spi)

 

Connected by 4-line spi (d/c hard pin), then works normally

 

But I would like all this to work only on the 3rd lines of spi

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Show a schematic of your connections.

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
Last Edited: Wed. Jan 15, 2020 - 06:21 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

The typical Nokia screen is configured for 4-Wire SPI.   There is no access to PS1, PS0 signals.

 

The datasheet says:

9 SERIAL INTERFACES
Communication with the microcontroller is achieved via a
clock-synchronized serial peripheral interface.
One of four different serial interfaces may be selected
using the inputs PS1 and PS0; see Table 1.
Table 1 Interface selection

So you must use the DC line (Data/Command).

Yes,  you can probably tie /CSE low (Serial Chip Enable) but I would not advise it.

 

Seriously,   what do you expect to do with this display?   The Tiny13 has not got much Flash and even less SRAM.

You are not going to be able to do any serious graphics.   And a 96 letter 7x5 Font takes 480 bytes from your 1024 bytes of Flash.    And that is before you write the function to render text.

 

It is an interesting challenge.   Why did you choose such a poorly endowed chip?

 

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

david.prentice  awneil

Thanks.

 

I believe that attiny13 is an ideal microcontroller among weak, compact chips.
He has the required minimum of pins(+ the reset pin can be output), it is suitable for most tasks.

 

it is widespread.Can be desoldering from other devices.

 

I don’t need the whole alphabet, enough memory for 2 letters and 3 digits.
I want to use it to adjust the soldering iron and display the temperature.

 

And to use, for example, atmega8, where a minimum of legs and capabilities are involved - wasteful and what for, when such power is not needed.

And attiny13 is smaller than atmega8, which will reduce the size of the device.

 

Something like this.

Last Edited: Wed. Jan 15, 2020 - 10:43 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Try connecting Reset on the display to Reset on the AVR.  You may be able to reset the display with the AVRs long power-on/reset pulse.  You can also stretch the reset pulse from the AVR with a resistor 1000 ohm and capacitor 0.1 microfarad combination.  This frees a pin to use for D/C , which selects between data bytes received by the display and command bytes received.  The display needs seven wire connections,  Gnd, Vcc, MOSI, SCK, SCE (chip enable),  D/C, and the reset connected to the AVR reset.

Last Edited: Thu. Jan 16, 2020 - 12:52 AM