lcd interface with MC9S08PA16

cancel
Showing results for 
Search instead for 
Did you mean: 

lcd interface with MC9S08PA16

Jump to solution
1,842 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,015 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
232 Views
avditkohli
Contributor III

Hi Ian,

Thanks for the help. Coincidentally, I had tried using const float

minutes before your reply. It works :smileyhappy:

Avdit

On Wed, Jun 25, 2014 at 2:38 PM, Ian Legg <admin@community.freescale.com>

0 Kudos
233 Views
arpitaagarwal-b
NXP Employee
NXP Employee

Hello,

Using const will place the data in ROM. This is mentioned in .prm file.

Moreover, if you specifically want to put the data at particular flash location, you can define a data segment for the same.

Divide the ROM into two part (as per the size requirement) in .prm file as shown:

    ROM_USER                      =  READ_WRITE    0xC000 TO 0xC3E8; //for LUT of 1000 bytes

    ROM                                 = READ_ONLY    0xC3E9 TO 0xFF6F;

***************************************

in placements:

FLASH,

  INTO ROM;

**************************************

Use #pragma where LUT will be defined as shown:

#pragma DATA_SEG "FLASH"

float LUT_test[250];

#pragma DATA_SEG DEFAULT

************************************

This way, your LUT will be at the fixed location of 0xC000.

-Arpita

0 Kudos
233 Views
avditkohli
Contributor III

Hi,

I am sorry to keep on pestering you guys. Arpita, I tried Ian's way of

using const float test[250], which works fine but in my program I seem to

have the following problem:

int compute_stove_temp(int t)

{

temp2=t*0.0129; // converts to 3.3V scale

rt=((3.3/temp2)-1); // Rt div R =( (3.3)/(input) -1 )

stove=0;

for(q=0;q<=251;q++)

{

if(rt>=RtR[q])

{stove=q;} // if ratio matches then temperature =

q(location in the array)

else

{stove=0;}

}

return stove;

}

For some reason, the value stored in' stove' is always 251 no matter what

the input is. The computation before the for-loop works just fine.

Thanks for all your help,

Avdit

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

0 Kudos
233 Views
arpitaagarwal-b
NXP Employee
NXP Employee

Do you want the first location value (q) in stove where (rt>=RtR[q]) condition becomes true??

If so, you need to put break after stove=q; statement.

Else, if rt>=RtR[251], the 'for' loop will run to 251, changing stove values in every iteration and finally writing 251 in stove variable before returning.

Hence, you will always see 251 in stove.

0 Kudos
233 Views
avditkohli
Contributor III

Ofcourse! thank you!! I feel stupid right now

Avdit

On Wed, Jun 25, 2014 at 4:22 PM, Arpita Agarwal <

0 Kudos
233 Views
avditkohli
Contributor III

Hi,

I changed the settings to use float IEEE32 but in my program the

variable does not store any value when I compute the following:

float temp= (bcd/256)*3.3;

Regards,

Avdit

On Thu, Jun 19, 2014 at 1:11 PM, Avdit Singh Kohli <

0 Kudos
233 Views
iansmusical
Contributor V

Hi Avdit,

Are you using the "temp" variable elsewhere in your code, otherwise it's possibly being optimized away?

Thanks,

Ian

0 Kudos
233 Views
avditkohli
Contributor III

Got it!

Thanks for your help

On Thu, Jun 19, 2014 at 12:08 PM, Arpita Agarwal <

0 Kudos
233 Views
iansmusical
Contributor V

Hi Avdit,

Have a look here: Adding/Removing Floating Point Format for S08 Projects | MCU on Eclipse

Of course remembering that adding floating point will increase your runtime and may in fact be counter productive!

Ian

233 Views
avditkohli
Contributor III

Hi Arpita,

Thanks for your help. I changed the ADCO bit in order to enable

continuous conversion. I am using pin no.19 i.e. ADC1 so what should be

value I send to ADC_SC1? Only when I am sending 0b00100010 do i get any

value in my result but logically shouldn't i send 0b0010001. Anyways, that

value remains constant even when I change the incoming to-be-measured

voltage.

Regards,

Avdit

0 Kudos
233 Views
avditkohli
Contributor III

Hi Ian,

Thanks for all your help. I understood and made the changes you

suggested. The 0x80 allows access to the first letter on the first line of

the lcd. Basically i wanted to make sure that the data is written at the

right location. Do let me know if you think otherwise!

Regards,

Avdit

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

0 Kudos
233 Views
avditkohli
Contributor III

Hi,

Are the delays needed to be exactly as mentioned on the datasheet or

will a value greater than the specified one work as well? With my bus clock

frequency at 8MHz isnt the delay used sufficient. I did modify my program

to work with two kinds of delay. Do have a look

Thanks

Avdit

On Wed, May 28, 2014 at 7:04 PM, Ian Legg <admin@community.freescale.com>

0 Kudos
233 Views
iansmusical
Contributor V

Hello Avdit,

The delays must be at least the data sheet specified values and usually a little longer to allow for tolerances. There is no upper limit for the delays other than I think the E signal because it is effectively a clock. So, for example, after writing a character to the display one would usually wait 47us (or check the busy flag) but there is no reason why one couldn't wait 1 second, it just depends how fast one needs to communicate with the display.

Having looked at your code it might be personal preference but you might be better using the RTC peripheral to generate time delays as opposed to software loops? You'd then have known length delays that are not dependant on the bus clock frequency etc.

As I can see there are no delays (47us+) after you write each character of your display message or suitable delays after the commandwrite(0x30) sequence. Again check the data sheet as I think there needs to be 4.5ms delays or similar between those commands?

Hope this helps.

Ian