lcd interface with MC9S08PA16

cancel
Showing results for 
Search instead for 
Did you mean: 

lcd interface with MC9S08PA16

Jump to solution
1,833 Views
avditkohli
Contributor III

hi,

i am trying to interface LCD hd44780 or similar to a microcontroller MC9S08PA16 but seem to get errors in LCD_CTRL_PORT, SFRPAGE, SFRPAGE_SAVE lines along with a few others. Please bare with me as i am new to freescale and code warrior. I have attached the main file if you wish to take a look.

 

Avdit

Original Attachment has been moved to: main.c.zip

Labels (1)
Tags (2)
1 Solution
1,006 Views
arpitaagarwal-b
NXP Employee
NXP Employee

Hello Avdit,

Here are answers to your queries:

1. Analog input refers to the voltage you have applied on the pin like 1V or 3V. Maximum voltage can be the MCU supply voltage, ie, either 3.3V or 5V. 256 is the decimal number.

2. suppose your supply is 3.3V, resolution is 8bits, then 3.3V --> 255, 0.14V --> (0.14/3.3)*255 = ~10. So your ADC value will be around 10.

3. this is the number of bits for the adc result. like if 8bit, then maximum voltage will corresponds to 255(2^8-1), if 10bits, it will be 1023 (2^10-1) and so on..

Regarding code:

It seems you continuously want to read ADC. In this case, you can enable continuous conversion:

ADC_SC1_ADCO = 1; /*Continuous conversion enable*/

While reading the result:

while(!ADC_SC1_COCO);

  result = ADC_RL;

It should work. If it doesn't, let me know where your code is getting hanged.

Thanks and Regards

Arpita Agarwal

View solution in original post

33 Replies
776 Views
arpitaagarwal-b
NXP Employee
NXP Employee

Hello Avdit,

In your file, there is :

#define LCD_DAT_PORT P6 //LCD IS IN 8 BIT

#define LCD_CTRL_PORT P7 //3 control pins on P7

What is P6 and P7? Is this defined in the code?

It should be one of the port data registers where LCD control pins are connected.

-Arpita

776 Views
avditkohli
Contributor III

Hi,

Thanks for getting back to me. I solved that problem and have been

able to work my LCD to a certain extent. The only problem i am having is

that my output on the LCD is different every time I debug. For example if I

want to print "Logger" at times it'll print "L", '_', "Logg", "Logge" on

the same code. I have doubts on my delay/latch function. I have included my

code as an attachment

Avdit

On Wed, May 28, 2014 at 11:59 AM, Arpita Agarwal <

0 Kudos
776 Views
iansmusical
Contributor V

Hello Avdit,

From looking at your code I think you haven't added the required delays in the LCD set up code nor after you write each character to the LCD. It might also be necessary to wait x milliseconds after the LCD is powered up before initialising it.

One needs a delay of 47us after each character write. The E signal needs to be 1us wide (from memory).

It would be best to check the 44780 data sheet for exact timings.

Hope this helps.

Ian

776 Views
avditkohli
Contributor III

Hi,

I got the data to hold on the LCD by waiting using the busy flag but

that happened only once and since there has been no display on the LCD. I

have included my file. Do take a look, it is mostly self explanatory. The

delays can't be a problem now. Maybe its my check_busy_flag function but i

am not sure.

Avdit

On Thu, May 29, 2014 at 10:56 AM, Avdit Singh Kohli <

0 Kudos
776 Views
iansmusical
Contributor V

Hello Avdit,

Pleased you are making progress :-)

I don't think you need the delays in lcd_set_write_instruction() and lcd_set_write_data() because one is only setting port pins and it's only after the E signal that waits or checking the busy flag is necessary. Remembering that the E signal is what clocks information into the display.

Your busy flag check function is ok but you probably don't need to set the port as output, just input so as to read the busy flag.

You also can't check the busy flag in the display initialisation code until after a certain point. The diagram below might help:

LCD.jpg

Just remind me what lcd_write_byte(0x80) does in your while loop? I was thinking your were writing to display ram that might not be visible!?

Hope this helps,

Ian

0 Kudos
776 Views
avditkohli
Contributor III

Hi Ian,

The program works just fine now. You will not believe it but the LCD

module I was using required a voltage supply of 5V and while my supply was

3.3V it worked in a twisted manner or not at all. The datasheet mentioned

3.3V but on consulting the manufacturing did the necessity of using 5V

emerge.

Thanks for all your help. I am beginning my code for temperature sensing

now. Will let you know if I come up against any problems! :smileyhappy:

Avdit

On Tue, Jun 3, 2014 at 1:02 PM, Ian Legg <admin@community.freescale.com>

0 Kudos
776 Views
iansmusical
Contributor V

Hi Avdit,

You're welcome and pleased to hear it is all working now :-) I'd forgot 0x80 was the first position on line 1 but equally I don't normally use that command because out of reset the display location should already be set there.

You'll find that most LCDs require 5v even though there has been a shift to 3.3v. There is no reason why LCD logic can't be 3.3v but driving the LCD glass is the problem and the negative supply for the contrast, although that latter can be fixed with an addition chip (sometimes present on the LCD module). I did see an article for running a 5v LCD at 3.3v but with reduced contrast. Of course it depends on the chipset and what it sees a logic 1 at etc. The other solution is to use a level converter/shifter between the MCU and LCD.

Thanks,

Ian

776 Views
avditkohli
Contributor III

Hey Ian,

I had a few questions regarding operation of adc in mcs08pa4.

1. if my analog input is less than 256 will my output format of 8-bit be

sufficient?

2. how will the adc give values that are in fractions. suppose 0.14V?

3. Just to clarify, the 8,10,12 bit resolution is really the number of

samples?

Also my adc program does not seem to work although I followed almost all

instructions from the freescale adc tutorial. I would be highly obliged if

you took a look .

Regards,

Avdit

On Tue, Jun 10, 2014 at 1:22 PM, Ian Legg <admin@community.freescale.com>

0 Kudos
1,007 Views
arpitaagarwal-b
NXP Employee
NXP Employee

Hello Avdit,

Here are answers to your queries:

1. Analog input refers to the voltage you have applied on the pin like 1V or 3V. Maximum voltage can be the MCU supply voltage, ie, either 3.3V or 5V. 256 is the decimal number.

2. suppose your supply is 3.3V, resolution is 8bits, then 3.3V --> 255, 0.14V --> (0.14/3.3)*255 = ~10. So your ADC value will be around 10.

3. this is the number of bits for the adc result. like if 8bit, then maximum voltage will corresponds to 255(2^8-1), if 10bits, it will be 1023 (2^10-1) and so on..

Regarding code:

It seems you continuously want to read ADC. In this case, you can enable continuous conversion:

ADC_SC1_ADCO = 1; /*Continuous conversion enable*/

While reading the result:

while(!ADC_SC1_COCO);

  result = ADC_RL;

It should work. If it doesn't, let me know where your code is getting hanged.

Thanks and Regards

Arpita Agarwal

776 Views
avditkohli
Contributor III

Hey Arpita,

I got the program to work. Turns out, the hardware analog input was

configured correct. Also I wanted to ask you how can I use a float variable

with the uC I am using MCS08PA4 cause it displays an error eveytime I try

and use 'float'

Avdit

On Tue, Jun 17, 2014 at 4:40 PM, Avdit Singh Kohli <

0 Kudos
776 Views
arpitaagarwal-b
NXP Employee
NXP Employee

Hello Avdit,

Good to hear that your program is working now :smileyhappy:

As mentioned by Ian, do consider the advantages of adding "float" to your code because it will increase the size and execution time of your code.

-Arpita

0 Kudos
776 Views
avditkohli
Contributor III

Hi,

Quick question: I am trying to convert my binary output to BCD. How do I

transfer the MSB of my output to the LSB of a variable that I am using?

Thanks,

Avdit

On Wed, Jun 18, 2014 at 3:18 PM, Arpita Agarwal <

0 Kudos
776 Views
arpitaagarwal-b
NXP Employee
NXP Employee

You can transfer MSB of any variable using right shift operand (>>).

The statement will be:

out=in>>no_of_bits_to_be_shifted;

If it is a signed variable, proper masking of signed bit will be required.

776 Views
avditkohli
Contributor III

Hi,

I think you got my question wrong, Sorry! Suppose x=0b1010 and y=0b010

1, i wish to transfer the MSB of 'x' to LSB of 'y' to make y=0b1011

Regards,

Avdit

On Thu, Jun 19, 2014 at 9:39 AM, Arpita Agarwal <

0 Kudos
776 Views
arpitaagarwal-b
NXP Employee
NXP Employee

you can do it this way:

if(x>>3)

{

     y |= 0b0001;

}

else

{

     y &= 0b1110;

}

Hope this answers your question.

776 Views
avditkohli
Contributor III

Hi,

I am working on creating a LUT but since i have 250 float

values(runtime is not an issue) i will need to use FLASH memory. I am using

the following commands. My question is - Which register do I transfer these

commands for them to take effect?

#define FLASH_MASS_ERASE_CMD 0x41

#define FLASH_ERASE_CMD 0x40

#define FLASH_PROGRAM_CMD 0x20

#define FLASH_BURST_CMD 0x25

#define FLASH_BLANK_CHECK_CMD 0x05

In the datasheet, FCMD is mentioned but when I use that, it returns an

error.

Regards,

Avdit

On Mon, Jun 23, 2014 at 12:40 PM, Avdit Singh Kohli <

0 Kudos
776 Views
iansmusical
Contributor V

Hi Avdit,

Admittedly you may intentionally be wishing to program the FLASH with your LUT but you could equally create an array of 250 float values and make sure it is allocated to FLASH, then you don't have to worry about programming the FLASH :-)

Thanks,

Ian

0 Kudos
776 Views
avditkohli
Contributor III

Hi Ian,

That would make it a lot more simpler but how do make sure that the

array is allocated to flash directly?

Avdit

0 Kudos
776 Views
iansmusical
Contributor V

Hi Avdit,

I'm just guessing here without experimenting but you might be able to use something like #pragma CONST_SEG?

@ Arpita: can you assist?

Thanks,

Ian

0 Kudos
776 Views
iansmusical
Contributor V

Hi Avdit,

After experimenting it seems you can use:

  const float values[10] = {2.2};

My map file shows that "values" has been allocated to the .rodata section in FLASH :-)

Thanks,

Ian

0 Kudos