Would you like to react to this message? Create an account in a few clicks or log in to continue.

You are not connected. Please login or register

ADC error in code or in Atmega32 or human error?

2 posters

Go down  Message [Page 1 of 1]

Mistral



@Arcachofo, do you know if there maybe are some problems with the ADC in Atmega32?

Hi, I've been doing some 16F877A examples and the ADC went very good but now with Atm32 it's not so good. 

These are the two Circuit Digest examples and I labelled them AVR8_LM35 and AVR10_Voltmeter in my Github.
https://github.com/Alectus/AVR-MicroController-Examples/tree/main/AVR%20examples%20Hex-files
These hex-files are taken as soon as the original code compiled, not after changes made by me when trying some code-changes.

Orignal LM35 and Voltmeter are here:
https://circuitdigest.com/microcontroller-projects/avr-microcontroller-lm35-temperature-sensor-based-digital-thermometer
https://circuitdigest.com/microcontroller-projects/digital-voltmeter-using-avr-atmega32

They work but only when I press /Mclr or Power Circuit to get new values in the display. So I searched for other examples, one had a library that I don't have, another used fuse-bit settings which I don't know much about and the third is from Gadgetronicx
https://www.gadgetronicx.com/volt-amp-meter-using-avr-microcontroller/
Tried that one and only the LCD is working. Hex-file is also in the Github above. I have spent a total of 3 to 5 hours testing but still don't know what is going on.

Picture
https://raw.githubusercontent.com/Alectus/AVR-MicroController-Examples/main/AVR%201%20until%2010.PNG
Simu-file
https://github.com/Alectus/AVR-MicroController-Examples/blob/main/AVR%201%20until%2010_.simu

ADC error in code or in Atmega32 or human error? Avr_1_10

I tried it in 0.4.14 as well but that didn't improve it. Of course I am not asking for a code-explaining or a tutorial in fuse-bits but if you can confirm the ADC is correctly working and the problem is not inside the simulator than that would already be a great help. Thanks.

Mistral



This one is oke, buzzer starts beeping exactly at 0.6 Volts and above.
Atm32 at 16 MHz.

ADC error in code or in Atmega32 or human error? Ct_lm310

https://www.circuitstoday.com/using-adc-analog-digital-converter-avr

arcachofo

arcachofo

@Arcachofo, do you know if there maybe are some problems with the ADC in Atmega32?
atmega32 ADC is working for me.
No known issues with this.

These are the two Circuit Digest examples and I labelled them AVR8_LM35 and AVR10_Voltmeter in my Github.
https://github.com/Alectus/AVR-MicroController-Examples/tree/main/AVR%20examples%20Hex-files
These hex-files are taken as soon as the original code compiled, not after changes made by me when trying some code-changes.

Orignal LM35 and Voltmeter are here:
https://circuitdigest.com/microcontroller-projects/avr-microcontroller-lm35-temperature-sensor-based-digital-thermometer
https://circuitdigest.com/microcontroller-projects/digital-voltmeter-using-avr-atmega32

They work but only when I press /Mclr or Power Circuit to get new values in the display.
Yes, that is what that program do.
It takes one reading and prints it in the LCD forever, that's all.

https://www.gadgetronicx.com/volt-amp-meter-using-avr-microcontroller/
Tried that one and only the LCD is working. Hex-file is also in the Github above. I have spent a total of 3 to 5 hours testing but still don't know what is going on.
Look at comment section, many people have this problem.

To debug these problems use Mcu Monitor and add ADCL and ADCH to watch their values.
If the ADC conversion is working you will  see these values changing as the input voltages change:

ADC error in code or in Atmega32 or human error? Ramtab10

Mistral likes this post

Mistral



Thank you, it's good to know there are no known issues with the Atm32 ADC and in this one again it is indeed working fine.

ADC error in code or in Atmega32 or human error? Avr310

https://aki-technical.blogspot.com/2020/06/making-simple-5-v-voltmeter-with.html

Not always sure if everything is working in 0.4.15-SR1 because it is the 'only for testing' version, now I know it's not the ADC. I must have forgotten to read the comments under the gadgetronicx article, sorry about that. I did take a look at the end of the CD-examples and they showed a video where they set the LM35 on fire and the temperature was continues changing. I tried another one with LCD, added lcd.h and lcd.c (pfff) and it did compile. 
http://maxembedded.com/2011/06/the-adc-of-the-avr/comment-page-9/#comments
https://maxembedded.wordpress.com/2011/06/16/lcd-interfacing-with-avr/
https://github.com/damadmai/pfleury
I saw wires turn red in my 'IC-socket' but didn't get it working. Still have to find one ADC-LCD example that is going really good as with the 16F877A.
Not really knowing how to program it can be time consuming but I learn from it.
The links are for other readers who want to try it, I don't expect you to sift through it.

Your suggestion to use the Mcu-monitor is a good one, it is moving

ADC error in code or in Atmega32 or human error? Avr410

I even know what these ADCL and ADCH are, they are the 10 bits result from the ADC, the lower and the higher one. My widget is not completely good aligned, I tried several font scales but it stayed the same. I can read what it says so it's no problem. Thanks.   Wink

****************
edit 22:50 pm: 
adc-serial monitor working

ADC error in code or in Atmega32 or human error? Avr510

0010 0110 1110 = 622
https://binaryupdates.com/adc-in-avr-atmega32a-microcontroller/

You are right, it must be something in the Lcd part. Tried another library, no succes yet although it compiled.
https://mechatronicslabrpi.blogspot.com/2018/07/how-to-add-lcd-library-in-avr-studio.html 
https://github.com/sarful/how-to-add-lcd-library-in-avr-studio-avr-microcontroller-tutorial
Tomorrow another day, have a nice evening.



Last edited by Mistral on Thu May 06, 2021 11:08 pm; edited 3 times in total (Reason for editing : Lib added)

arcachofo

arcachofo

Your suggestion to use the Mcu-monitor is a good one, it is moving
So the problem is not in the ADC, it is probably in the part that prints data to LCD.

My widget is not completely good aligned, I tried several font scales but it stayed the same. I can read what it says so it's no problem.
This is (hopefully) solved in development version.

Mistral



So the problem is not in the ADC, it is probably in the part that prints data to LCD.

I agree, maybe it's something with delay too short. In one code I made the delays longer, see all the wires flashing but nada on the LCD.
https://www.rhydolabz.com/wiki/?p=7879

This one is displaying and behaving just like the previous mentioned CircuitDigest examples. You have to /Mclr it to get new value and this example also has video where turning the pot translates to immediate change in vlaues on the LCD screen.

https://www.engineersgarage.com/avr-microcontroller/how-to-use-internal-adc-of-avr-microcontroller-using-interrupts-part-28-46/

In int void() I changed this line
while(data!=' ')

to

while(data!='\0')

and the build succeed and this is the result

ADC error in code or in Atmega32 or human error? Avr610

So everything works fine except it is not updating by itself.
I am not going to try anymore, someday later it will become clear. Thanks for helping.

arcachofo

arcachofo

This one is displaying and behaving just like the previous mentioned CircuitDigest examples. You have to /Mclr it to get new value and this example also has video where turning the pot translates to immediate change in vlaues on the LCD screen.
Maybe there is some error in simulide in some ADC mode.
Probably related to Auto-Trigger.
I will have a closer look...

Mistral



I wish I could be of more help to pin point it but I'm not very good in programming. Yesterday I experienced two types of difficulties, the Mclr reset condition and the other one with lcd.h kind of type libraries that compiled but didn't make the Lcd active. The second one I am almost 100% sure that more program skilled people can solve this easily because the Lcd is working, nothing wrong with that. Adc is working good too so probably it is in a combination of the two that this start/stop behaviour occurs. Good luck finding it, it is not blocking with what I am doing, as you have seen the examples are pretty much independent of each other, more parallel than serial chained related. Thanks.

The next one is with ultra sonic sensor and with interrupts and should display continues. I'll let you know how that goes.

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

This is the source code
https://circuitdigest.com/microcontroller-projects/distance-measurement-using-hc-sr04-avr
https://circuitdigest.com/sites/default/files/circuitdiagram_mic/AVR-Ultrasonic-Sensor-Circu.gif
Program compiled at once, no changes there and everything is working except only value visible on Lcd is ''0 cm''.
When I change the sensors' input voltage I see a change on the scope display but it does not transfer to Lcd. Pressing Mclr or Power Circuit buttons did not make a value appear on the screen.
Tried it again after removing IC-'socket' dipswitch but that made no difference. 
This is just one example that I tried with Atmega and Ultra sonic so no conclusions can be made yet, not by me at least. I'll look for more examples and see how that goes. I read you are busy with I2C so let me gather some more information to make it easier to find a possible cause. 

ADC error in code or in Atmega32 or human error? Avr11_10

ADC error in code or in Atmega32 or human error? Avr12_10


Ps, a similar example with 16F877A worked fine.


ADC error in code or in Atmega32 or human error? Cd22-u11

>>
https://circuitdigest.com/microcontroller-projects/interfacing-ultrasonic-sensor-hc-sr04-with-pic16f877a



Last edited by Mistral on Fri May 07, 2021 12:04 pm; edited 3 times in total (Reason for editing : ***** + Ps)

Mistral



Yippie!   Very Happy
Two things are going good now, adding a lcd-library and direct transfer to lcd screen.
The code and the schematic are here but both are not complete.
https://www.electronicwings.com/avr-atmega/ultrasonic-module-hc-sr04-interfacing-with-atmega1632
Tried to compile it but had to add not only an existing .h-file but also a .c file, these ones >
https://www.electronicwings.com/images/topic_content_attachments/Thu-06-16-22-58-08.LCD_16x2_C_file.c
https://www.electronicwings.com/images/topic_content_attachments/Thu-06-16-22-58-24.LCD_16x2_H_file.h
Didn't know that only adding a header file is not enough so I will try again with some ADC-LCD examples later.
After that it compiled good so I set it up like in the scheme from Elecwings, that did not work. Luckily my IC-socket design shows which unused pins are active because they turn red. Turns out that in the .c-file they use a slightly different pin-configuration so I apllied that and then the display came to live. To make it in range I had to set the Volt-source to 0-1V. Turn the knob and value changes on the Lcd.

ADC error in code or in Atmega32 or human error? Avr_lc10

This is the hex-file:

Code:
:100000000C94A7000C94C4000C94C4000C94C4007D
:100010000C94C4000C94C4000C94C4000C94C40050
:100020000C94C4000C942D010C94C4000C94C400D6
:100030000C94C4000C94C4000C94C4000C94C40030
:100040000C94C4000C94C4000C94C4000C94C40020
:100050000C94C40000407A10F35A00A0724E1809A4
:100060000010A5D4E80000E87648170000E40B541F
:10007000020000CA9A3B000000E1F50500008096EE
:100080009800000040420F000000A0860100000020
:10009000102700000000E8030000000064000000DA
:1000A00000000A00000000000100000000002C76A3
:1000B000D888DC674F0823DFC1DFAE59E1B1B796BE
:1000C000E5E3E453C63AE651997696E8E6C284261B
:1000D000EB898C9B62ED407C6FFCEFBC9C9F40F2F7
:1000E000BAA56FA5F490055A2AF75C936B6CF96773
:1000F0006DC11BFCE0E40D47FEF520E6B500D0ED38
:10010000902E0300943577050080841E080000209F
:100110004E0A000000C80C333333330F986E12833D
:100120001141EF8D2114893BE65516CFFEE6DB1811
:10013000D1844B381BF77C1D901DA4BBE4242032D6
:1001400084725E228100C9F124ECA1E53D271124CF
:100150001FBECFE5D8E0DEBFCDBF10E0A0E6B0E027
:10016000E6E8FAE002C005900D92AA37B107D9F788
:1001700020E0AAE7B0E001C01D92AC37B207E1F77A
:100180000E9444010C9441050C94000088BB84E05B
:1001900085BB8FEC97E00197F1F700C0000015BA1E
:1001A0008FE097E20197F1F700C00000089588BB47
:1001B00084E185BB8FEC97E00197F1F700C0000068
:1001C00080E185BB8FE097E20197F1F700C0000066
:1001D00008958FE39CE90197F1F700C000008FEFCD
:1001E00084BB87BB88E30E94C60081E00E94C600F2
:1001F0008CE00E94C60080E80E94C60008950F931C
:100200001F93CF93DF938C01C0E0D0E003C00E9426
:10021000D7002196F801EC0FFD1F80818111F7CFE7
:10022000DF91CF911F910F910895CF93DF93EA0152
:10023000813031F4862F8F7080680E94C60007C01D
:10024000823029F4862F8F70806C0E94C600CE0108
:100250000E94FF00DF91CF9108951F920F920FB679
:100260000F9211248F939F9380917A0090917B003D
:10027000019690937B0080937A009F918F910F90CD
:100280000FBE0F901F901895CF93DF93CDB7DEB7B9
:100290002A970FB6F894DEBF0FBECDBF81E08ABBB0
:1002A0008FEF82BB0E94E90040E650E060E081E011
:1002B0000E941501789484E089BF1FBC8BB38160D4
:1002C0008BBB2AE12A95F1F700C08BB38E7F8BBBE5
:1002D0001DBC1CBC81E48EBD80E288BF84E088BF69
:1002E00008B605FEFDCF1DBC1CBC81E08EBD80E2C2
:1002F00088BF84E088BF10927B0010927A0008B615
:1003000005FEFDCF66B577B580E090E00E942C0237
:1003100029E23CE349EE53E40E94B8019E012F5FBD
:100320003F4F7901890122E042E00E94B802D701E3
:100330000D900020E9F7119787E0EBE6F0E00190DF
:100340000D928A95E1F742E750E060E082E00E947A
:100350001501A70167E082E00E9415013FEF81EEE1
:1003600094E0315080409040E1F700C00000A6CFFB
:100370000E94CC010C947E020E94770258F00E94E9
:10038000700240F029F45F3F29F00C94670251118C
:100390000C94B2020C946D020E948F0268F39923B0
:1003A000B1F3552391F3951B550BBB27AA27621771
:1003B0007307840738F09F5F5F4F220F331F441F7E
:1003C000AA1FA9F335D00E2E3AF0E0E832D09150B2
:1003D0005040E695001CCAF72BD0FE2F29D0660F9F
:1003E000771F881FBB1F261737074807AB07B0E8E2
:1003F00009F0BB0B802DBF01FF2793585F4F3AF0E8
:100400009E3F510578F00C9467020C94B2025F3F56
:10041000E4F3983ED4F3869577956795B795F7956D
:100420009F5FC9F7880F911D9695879597F9089555
:10043000E1E0660F771F881FBB1F621773078407F1
:10044000BA0720F0621B730B840BBA0BEE1F88F700
:10045000E0950895E89409C097FB3EF49095809547
:10046000709561957F4F8F4F9F4F9923A9F0F92F7A
:1004700096E9BB279395F695879577956795B795F8
:10048000F111F8CFFAF4BB0F11F460FF1BC06F5FDE
:100490007F4F8F4F9F4F16C0882311F096E911C0F0
:1004A000772321F09EE8872F762F05C0662371F011
:1004B00096E8862F70E060E02AF09A95660F771F25
:1004C000881FDAF7880F9695879597F9089597F919
:1004D0009F6780E870E060E008959FEF80EC0895EA
:1004E00000240A9416161706180609060895002413
:1004F0000A9412161306140605060895092E03948D
:10050000000C11F4882352F0BB0F40F4BF2B11F400
:1005100060FF04C06F5F7F4F8F4F9F4F089557FD5F
:100520009058440F551F59F05F3F71F04795880F61
:1005300097FB991F61F09F3F79F0879508951216F8
:1005400013061406551FF2CF4695F1DF08C01616A4
:1005500017061806991FF1CF869571056105089455
:100560000895E894BB2766277727CB0197F908956C
:10057000EF920F931F93CF93DF93E80147FD02C0E3
:1005800034E001C034E1042E000C550B57FF03C0CA
:10059000519541955109E32E022F242FAE010E945F
:1005A000D802CE01DF91CF911F910F91EF90089566
:1005B000A9E0B0E0EEEDF2E00C9410056A01122F14
:1005C000B02E2BE3201720F0FF24F394F00E02C08E
:1005D0002CE3F22E0F2D27E0AE014F5F5F4F0E94FC
:1005E0003204BC014981842F8970813031F0E1FCF3
:1005F00006C0E0FE06C090E205C09DE203C09BE29B
:1006000001C090E05E2D507143FF3CC0911102C0CB
:1006100083E001C084E0811718F4212F281B01C05A
:1006200020E051110BC0F601822F30E2882319F02F
:1006300031938150FBCFC20ED11C20E0992329F0C9
:10064000D6019C93F60131966F01C6010396E2FE36
:100650000AC03EE4D6013C9341E411964C931197B5
:1006600012963C9306C03EE6F601308341E6418394
:100670003283FC01322F40E2332309F442C041931C
:100680003150FACF42FF44C0911102C083E001C053
:1006900084E0811718F4212F281B01C020E051119C
:1006A0000BC0F601822F30E2882319F0319381507C
:1006B000FBCFC20ED11C20E0992329F0D6019C93D8
:1006C000F60131966F01C6010396E2FE0BC039E4D4
:1006D000D6013C933EE411963C93119736E4129672
:1006E0003C9307C039E6F60130833EE6318336E6B7
:1006F0003283FC01322F40E2332319F04193315011
:10070000FBCFFC01E20FF11D10828EEF9FEFA6C020
:1007100021E030E0911102C020E030E0161617060B
:100720001CF4FB01319602C0E1E0F0E02E0F3F1F08
:10073000BB2021F0EB2DF0E0319602C0E0E0F0E0CC
:100740002E0F3F1FE12FF0E02E173F071CF4121B66
:10075000212F01C020E08E2D887159F4F601822FDF
:1007600030E2882319F031938150FBCFC20ED11CA7
:1007700020E0992329F0D6019C93F60131966F0170
:1007800051110BC0F601822F90E3882319F0919349
:100790008150FBCFC20ED11C20E00F2D060F9A8195
:1007A000342F307144FF03C0913309F40150101607
:1007B00024F4093018F008E001C001E0AB0177FF34
:1007C00002C040E050E0FB01E41BF50BA1E0B0E00B
:1007D000AC0FBD1FEA0FFB1F8EE2A82E4B01801A43
:1007E00091080B2D10E01195019511094F3FBFEFB6
:1007F0005B0721F4D601AC9211966D016417750761
:100800002CF08416950614F4818101C080E34150D8
:1008100051093196D60111967D014017510724F0F8
:10082000D6018C936701E2CF6417750739F49633CC
:1008300020F4953319F4311101C081E3F60180836E
:10084000F701822F90E2882319F091938150FBCF1A
:10085000F701E20FF11D108280E090E02996ECE0B4
:100860000C942C05283008F027E03327DA01990F83
:10087000311D87FD916000966105710539F4326084
:100880002E5F3D9330E32A95E1F708959F3F30F0C6
:1008900080387105610509F03C5F3C5F3D93913004
:1008A00008F08068911DDF93CF931F930F93FF9201
:1008B000EF92192F987F9695E92F96959695E90FC7
:1008C000FF27E255FF4F99273327EE24FF24A70186
:1008D000E70105900894079428F4360FE71EF81EE8
:1008E000491F511D660F771F881F991F0694A1F796
:1008F0000590079428F4E70EF81E491F561FC11DE6
:10090000770F881F991F661F0694A1F7059007941B
:1009100028F4F80E491F561FC71FD11D880F991FB5
:10092000661F771F0694A1F70590079420F4490FDE
:10093000561FC71FD81F990F661F771F881F069461
:10094000A9F784911095177041F0D695C7955795E2
:100950004795F794E7941A95C1F7E4E5F0E06894B9
:100960001590159135916591959105907FE273955C
:10097000E118F10A430B560BC90BD009C0F7E10C83
:10098000F11E431F561FC91FD01D7EF4703311F492
:100990008A95E6CFE894015030F0080F0AF400275A
:1009A000021708F4202F2395022F7A3328F079E3D9
:1009B0007D932A95E9F710C07D932A9589F60694D0
:1009C00097956795379517951794E118F10A430B9A
:1009D000560BC90BD00998F023957E9173957A3305
:1009E00008F070E37C932013B8F77E9170617D93DB
:1009F00030F0839571E37D9370E32A95E1F711243C
:100A0000EF90FF900F911F91CF91DF91992787FD74
:100A1000909508952F923F924F925F926F927F929E
:100A20008F929F92AF92BF92CF92DF92EF92FF92FE
:100A30000F931F93CF93DF93CDB7DEB7CA1BDB0BAA
:100A40000FB6F894DEBF0FBECDBF09942A8839884F
:100A500048885F846E847D848C849B84AA84B98456
:100A6000C884DF80EE80FD800C811B81AA81B98162
:100A7000CE0FD11D0FB6F894DEBF0FBECDBFED0176
:060A80000895F894FFCF79
:100A8600556C747261736F6E69630020636D20200C
:0A0A9600200044697374203D200025
:00000001FF

Mistral



At last - a working ADC-LCD combination that responds without resets. 

I didn't have to compile the program, I downloaded it from the Supporting Files section below the article and loaded the LM35_Sensor.hex as Firmware to the uC. However, it turns out to be compiled for Atm32 and not for 16. 

https://www.electronicwings.com/avr-atmega/lm35-temperature-sensor-interfacing-with-atmega1632

I don't know why other examples had to be stop/started to get a value on the screen but if you still want to check that, than maybe this example can be used for comparison.  Wink


ADC error in code or in Atmega32 or human error? Lm32_s10

arcachofo

arcachofo

I don't know why other examples had to be stop/started to get a value on the screen
Probably an error in simulide with ADC Auto-trigger.
But I still have to check...

Mistral



arcachofo wrote:
Probably an error in simulide with ADC Auto-trigger.

I just had to rewire and 'rewrite' a CircuitDigest example and if their examples can't be trusted than who is to 'blame' ?

Original says LCD is on PortB but I had to switch it to PortA and make B input.

https://circuitdigest.com/microcontroller-projects/touch-keypad-interfacing-with-avr-atmega32

https://circuitdigest.com/sites/default/files/circuitdiagram_mic/Touch-keypad-interfacing-ci.gif

Adjusted code by me >
Code:
/*
 * AVR12_TouchPad.c
 *
 * Created: 07/05/2021 23:58:55
 * Author : https://circuitdigest.com/microcontroller-projects/touch-keypad-interfacing-with-avr-atmega32
 */

#include <avr/io.h>

//header to enable data flow control over pins

#define F_CPU 1000000

//telling controller crystal frequency attached

#include <util/delay.h>

//header to enable delay function in program


#define    E   5

//giving name “enable”  to 5th pin of PORTD, since it Is connected to LCD enable pin

#define RS  6

//giving name “registerselection” to 6th pin of PORTD, since is connected to LCD RS pin

void send_a_command(unsigned char command);

void send_a_character(unsigned char character);

void send_a_string(char *string_of_characters);

int main(void)

{

 DDRB = 0;  ///////////////  ********

 // putting portB and portD as output pins

 DDRD = 0xFF;

 DDRA = 0xFF;//porta as input  ///////////////////*******************

 _delay_ms(50);//giving delay of 50ms

 int key=0;//allocating integer to reset the LCD once it reaches its display limit

 int keypressed=0;//integer for storing matrix value

 send_a_command(0x01); //Clear Screen 0x01 = 00000001

 _delay_ms(50);

 send_a_command(0x38);//telling lcd we are using 8bit command /data mode

 _delay_ms(50);

 send_a_command(0b00001111);//LCD SCREEN ON and courser blinking

 send_a_string("PRESS A KEY");//displaying a string

 send_a_command(0x80 + 0x40 +0);// moving courser to second line of LCD

 while(1)

 {

 if (bit_is_set(PINB,0))

 {

 send_a_string("1");//if pin0 goes high show” 1”

 _delay_ms(220);

 key++;

 }

 if (bit_is_set(PINB,1))

 {

 send_a_string("2");// if pin1 goes high show” 2”

 _delay_ms(220);

 key++;

 }

 if (bit_is_set(PINB,2))

 {

 send_a_string("3");// if pin2 goes high show” 3”

 _delay_ms(220);

 key++;

 }

 if (bit_is_set(PINB,3))

 {

 send_a_string("4");// if pin3 goes high show” 4”

 _delay_ms(220);

 key++;

 }

 if (bit_is_set(PINB,4))

 {

 send_a_string("5");// if pin4 goes high show” 5”

 _delay_ms(220);

 key++;

 }

 if (bit_is_set(PINB,5))

 {

 send_a_string("6");// if pin5 goes high show” 6”

 _delay_ms(220);

 key++;

 }

 if (bit_is_set(PINB,6))

 {

 send_a_string("7");// if pin6 goes high show” 7”

 _delay_ms(220);

 key++;

 }

 if (bit_is_set(PINB,7))

 {

 send_a_string("8");// if pin7 goes high show” 8”

 _delay_ms(220);

 key++;

 }

 if (key==16)//if 16 characters are shown on LCD

 {

 send_a_command(0x01); //clear lcd

 send_a_string("PRESS A KEY");//display string

 send_a_command(0x80 + 0x40 +0);//move courser to second line.

 key=0;

 }

 }

}

void send_a_command(unsigned char command)

{

 PORTA = command;

 PORTD &= ~ (1<<RS); //putting 0 in RS to tell lcd we are sending command

 PORTD |= 1<<E; //telling lcd to receive command /data at the port

 _delay_ms(50);

 PORTD &= ~1<<E;//telling lcd we completed sending data

 PORTA= 0;

}

void send_a_character(unsigned char character)

{

 PORTA= character;

 PORTD |= 1<<RS;//telling LCD we are sending data not commands

 PORTD |= 1<<E;//telling LCD to start receiving command/data

 _delay_ms(50);

 PORTD &= ~1<<E;//telling lcd we completed sending data/command

 PORTA = 0;

}

void send_a_string(char *string_of_characters)

{

 while(*string_of_characters > 0)

 {

 send_a_character(*string_of_characters++);

 }

}

ADC error in code or in Atmega32 or human error? Avr13_10

Sponsored content



Back to top  Message [Page 1 of 1]

Permissions in this forum:
You cannot reply to topics in this forum