ADC with 16f877a

Discussion in 'Embedded Systems and Microcontrollers' started by Alicp, Mar 12, 2014.

  1. Alicp

    Thread Starter New Member

    Mar 12, 2014
    7
    0
    hello can you help about this source code(in image) the result not display
     
    • 1.jpg
      1.jpg
      File size:
      176.2 KB
      Views:
      55
    • 2.jpg
      2.jpg
      File size:
      198.4 KB
      Views:
      39
  2. ericgibbs

    AAC Fanatic!

    Jan 29, 2010
    2,504
    380
    hi,
    Does the label 'Value' appear on the LCD.?

    What Xtal frequency have you set.?
     
  3. Alicp

    Thread Starter New Member

    Mar 12, 2014
    7
    0
    the label 'Value' not appear on the LCD.
    freq=8MHZ
     
  4. tshuck

    Well-Known Member

    Oct 18, 2012
    3,531
    675
    Without knowing about, or having ever used, MikroC, there is probably another routine for initializing a LCD in 4 bit mode (the initialization sequence is different).

    Other than that, can you view the ADC result when you run the simulation in debug mode?

    Have you verified the LCD is working?

    In a side note, I think that these simulators can do you a real disservice as it allows you to run code in a PIC without a clock.
     
  5. Alicp

    Thread Starter New Member

    Mar 12, 2014
    7
    0
    exist a loop in L_Delay_5500us3

    L_Delay_5500us3:
    0x0013 0x0BFD DECFSZ R13, 1
    0x0014 0x2813 GOTO L_Delay_5500us3
     
  6. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    First make sure your LCD functions work. Start with writing a program that write "hello world" on the LCD Before such a program works it is no point in going further. Then write a simple routine that convert the the 12 bit ADC value to a ASCII format number and use the working LCD routine to dump latter ADC ASCII number on the LCD
     
    THE_RB likes this.
  7. tshuck

    Well-Known Member

    Oct 18, 2012
    3,531
    675
    Yes, a blocking delay will use a loop.

    Agreed, but a small point - it's a 10-bit ADC...
     
  8. Alicp

    Thread Starter New Member

    Mar 12, 2014
    7
    0
    lcd work but adc_read(); don't work
    can any one give me an example on adc with pic16f877a with source code since i'm beginner in microcontroller?
     
  9. tshuck

    Well-Known Member

    Oct 18, 2012
    3,531
    675
    You will need to set the ANSEL and comparator registers for the analog functions to work.

    See here.
     
  10. ericgibbs

    AAC Fanatic!

    Jan 29, 2010
    2,504
    380
    hi,
    You said in post #3, that the 'text label= value' is not being displayed, so the LCD is not working.

    Can you post the full hex code?, I do not use MickroC
     
  11. Ian Rogers

    Member

    Dec 12, 2012
    158
    29
    Look at your 12 messages!!!!! You'll find that MCLR needs to be connected to 5v rail!!
     
  12. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    @Alicp
    As a beginner it could be smart to always include this code in your program
    Code ( (Unknown Language)):
    1.  
    2. ANSEL  = 0x00;              // Configure all pins with ADC option
    3. ANSELH = 0;                 // as digital I/O
    4.   C1ON_bit = 0;               [I]// Disable comparators[/I]
    5.   C2ON_bit = 0;
    6.  
    7.  
    And if you need analog input rather set the needed bit in the corresponding ANSEL(H) register bits separately. By default after a reset pins with ADC input function are configurated as analog input NOT digital IO
     
  13. Alicp

    Thread Starter New Member

    Mar 12, 2014
    7
    0
    :02000000d52cfd
    :10000600033083120313fd00fd0b072800000000d8
    :020016000800e0
    :020018000800de
    :10001a00023083120313fc00c830fd00fd0b1328c5
    :06002a00fc0b1328080086
    :0e003000f201f101f001f801f30100300800c7
    :10003e0083120313dd1b25288711262887155d1bc8
    :10004e002a2807112b280715dd1a2f28871030288c
    :10005e0087145d1a34280710352807143a183928e2
    :10006e0006143a28061086140c208610dd19412835
    :10007e008711422887155d1946280711472807154d
    :10008e00dd184b2887104c2887145d185028071050
    :10009e00512807143a1855280614562806108614a7
    :1000ae000c2086103a1c5d280d205e2803200800c7
    :1000be007b15fb1f69280130f300f201f101f001fd
    :0800ce00fa0df20cff300800ee
    :0800d600fa1ff21300300800cc
    :1000de00fb14fb1f7928ff30f300f200f100f00053
    :0800ee00fa0df20cff300800ce
    :1000f600831203135b08f2007208f100f20a5c082f
    :10010600f000dc0a700884000008f0007108840022
    :1001160070088000710884000008031993287f285e
    :060126005b08f000080078
    :10012c0083120313fb017308031d77080319ed28d1
    :10013c0072087606fa007708f3077e30031caa28ab
    :10014c00f3020318f028ad28f302031cf3287208fd
    :10015c00f8007108fc007008fd00f817f617031082
    :10016c00f201f101f0011830a0007d1cc7287408c1
    :10017c00f00775080318750ff10776080318760f4a
    :10018c00f207f20cf10cf00cf80cfc0cfd0c03104b
    :10019c00a00bbb28f21bd728f80df00df10df20dba
    :1001ac00f3037b1b701ce928f81fe928f00a0319dc
    :1001bc00f10a0319f20a031de928f20cf10cf00cf8
    :1001cc00f30a0319f028fa1ff2130030f528013056
    :1001dc001820f52802306f20f52804305f2000002d
    :0201ec00080009
    :0e01ee000000000000000000000000000800fb
    :0e01fc008312031333088a00320882000800c1
    :10020a00a0017208031d1a297108f2007008f10092
    :10021a00f001a0157208031d1a297108f200f101f4
    :10022a00a01120167208031928292008f302031db9
    :10023a00031c2c290310f21b3029f00df10df20dcd
    :10024a00f30b20292c290130fc0018203329023015
    :0e025a00fc005f2033290430fc006b200800fc
    :1002680083120313fa017308031d7a147708031d18
    :10027800fa147a0803198029033a03194b297a18c2
    :100288004829f61f7e297c29f21f7c297e297208bd
    :100298008039fa00f21376088039f6137a060319c2
    :1002a80059297a0803197c297e29770873020319ca
    :1002b8006029031c742978297608720203196729b2
    :1002c800031c742978297508710203196e29031c07
    :1002d8007429782974087002031980290318782969
    :1002e800fa0803197e297c29fa0803197c297e2932
    :1002f800031408000310080003140315080008007d
    :10030800831203133a105b08dd001f203a1408001b
    :1003180083120313f8010830fc00700df80d7408ff
    :10032800f80203189929f8070310f00dfc0b91291e
    :020338000800bb
    :10033a0083120313d901da014e08d5004f08d600fb
    :10034a005008d7005108d8005808ff3a031db729aa
    :10035a005708ff3a031db7295608ff3a031db72964
    :10036a005508ff3a031dc1295208db002730dc007b
    :10037a007b200330f000962b0130d300d71fd02901
    :10038a0080305706f0007008d700d30a520884005c
    :10039a002d308000d20a0030f0005806031ddf29f4
    :1003aa0070085706031ddf2970085606031ddf294a
    :1003ba005508003a031de8295208db002530dc0005
    :1003ca007b20f001962b5808ff3a031df62957089f
    :1003da00003a031df6295608003a031df629550866
    :1003ea00003a031d002a5208db002130dc007b2082
    :1003fa005308f000962b0030f4000030f50000306e
    :10040a00f6007f30f7005508f0005608f10057084b
    :10041a00f2005808f3003421013003180030f000cc
    :10042a0070080319332a5508f0005608f1005708d6
    :10043a00f2005808f3000030f4000030f5002030d4
    :10044a00f6008230f70096207008d5007108d600b1
    :10045a007208d7007308d800da03002a0030f400c3
    :10046a000030f5002030f6008230f7005508f00021
    :10047a005608f1005708f2005808f30034210130f9
    :10048a00031c0030f00070080319662a5508f000b2
    :10049a005608f1005708f2005808f300cd30f4006e
    :1004aa00cc30f5004c30f6007b30f700962070080f
    :1004ba00d5007108d6007208d7007308d800da0a86
    :1004ca00332aff305505f800ff305605f9007f3012
    :1004da005705fa0000305805fb007808f40079083f
    :1004ea00f5007a08f6007b08f700f40df50df60d15
    :1004fa00f70d741000305505f00000305605f10074
    :10050a0000305705f200ff305805f3007008d50097
    :10051a007108d6007208d7007308d8007408550409
    :10052a00f00075085604f10076085704f2007708bf
    :10053a005804f3007008d5007108d6007208d70075
    :10054a007308d8007f305802f0007008d4000130d8
    :10055a00d8007008f4005508f0005608f100570852
    :10056a00f2005808f30074080319c22af00df10dbd
    :10057a00f20df30d7010ff3eb92a7008d50071080c
    :10058a00d6007208d7007308d8005808303ef00029
    :10059a005208840070088000d20a80305a06f0009f
    :1005aa008030013a7002031ce32a8030063af000d8
    :1005ba0080305a067002031ce32aea2a5208840091
    :1005ca002e308000d20a0130d9000630d4005408f7
    :1005da00003a0319482bd8015508f0005608f100d3
    :1005ea005708f2005808f300f00df10df20df30d63
    :1005fa007010f00df10df20df30d70105508f007a3
    :10060a0056080318560ff10757080318570ff20731
    :10061a0058080318580ff3077008d5007108d60058
    :10062a007208d7007308d8005508f0005608f10080
    :10063a005708f2005808f300f00df10df20df30d12
    :10064a0070107008d5007108d6007208d7007308b8
    :10065a00d8005808303ef000520884007008800024
    :10066a00d20a5908003a031d462bda035a08003aff
    :10067a00031d462b520884002e308000d20a013016
    :10068a00d900d403ec2aff30520784000008303a1c
    :10069a00031d512bd203482bff3052078400000858
    :1006aa002e3a031d592bd2035a08003a0319922bea
    :1006ba005208840065308000d20a80305a06f00061
    :1006ca008030003a70020318722b520884002d30d1
    :1006da008000d20a5a08003cda005a08d4005a08a4
    :1006ea00093c0318842b0a30f4005408f0008c21ca
    :1006fa003030f0075208840070088000d20a0a30ad
    :10070a00f4005408f0008c217808f0003030f0072b
    :10071a005208840070088000d20a520884008001be
    :04072a00f0010800d2
    :10072e0083120313cf014f084e07840000080319ec
    :10073e00a82b4f084e0784000008db008421cf0a47
    :04074e009a2b0800da
    :1007520083120313fb01fa01f9018030f800f10c56
    :10076200f00c031cbd2b7408f90775080318750fec
    :10077200fa070318fb0a0310f01fc52b7408fa07c7
    :1007820075080318750ffb07fb0cfa0cf90cf80c33
    :10079200031cb02b7b08f3007a08f2007908f10001
    :0607a2007808f0000800d9
    :1007a800831203137008f8007108f000f101f201d8
    :1007b800f301fb01fc019630f300fa017008f10027
    :0c07c8007808f000f801f201052108009b
    :1007d40083120313f801f9011030fc00710df80db8
    :1007e400f90d7408f8027508031c750ff902031853
    :1007f400022c7408f80775080318750ff90703101d
    :0a080400f00df10dfc0bf02b0800c5
    :10080e00c330831203139f05c0309f004e08f000c3
    :10081e00f00d7010f00d701070089f0483169f1766
    :10082e0083121f14f7209f149f1c1f2c00001b2cdb
    :10083e001f101e08f100f00183161e08f004003090
    :04084e00f1040800a9
    :10085200ff3083120313bb00ff30bc00ff30bd002a
    :10086200ff30c3309f05c0309f0083169f1783124d
    :040872001f14080047
    :10087600fe208a110a128000840ab20a0319b30afa
    :08088600f003031d3b2c0800e8
    :10088e0083160313861006100710871007118711a1
    :10089e0083128610061087110711871007100d207e
    :1008ae000d200d208714071486140c2086100d20a1
    :1008be0086140c2086100d2086140c2086100d2018
    :1008ce00071086140c2086100d2086140c2086101e
    :1008de008710871586140c2086100d20871107149b
    :1008ee0086140c208610071086140c2086100d20fe
    :1008fe0086140c208610071486140c2086100d20ea
    :10090e00071086140c2086108715071587140714f8
    :0c091e0086140c2086100d203a140800ee
    :10092a00a72c803083120313ce00ba2cc030ce001d
    :10093a00ba2c9430ce00ba2cd430ce00ba2c8030e7
    :10094a00ce00ba2c831203134e08013a0319962ccf
    :10095a004e08023a03199b2c4e08033a03199e2c9f
    :10096a004e08043a0319a12ca42c4f03f0004e0898
    :10097a00f0077008ce007008dd001f203a10d10180
    :10098a0051085007840000080319d32c5108500756
    :10099a0084000008db008421d10ac52c3a1408001f
    :1009aa004225ff30831603138500472429240317a1
    :1009ba00871388130c300313dd001f200230ce008a
    :1009ca00072470088312b8007108b9000530f400d2
    :1009da000030f500a923ff30f4000330f500ea23c4
    :1009ea00d4237008b4007108b5007208b600730801
    :1009fa00b7007008ce007108cf007208d0007308e3
    :100a0a00d1003e30d2009d210130ce000330cf000c
    :100a1a002b30d00095240230fb004530fc00a93071
    :100a2a00fd00fd0b162dfc0b162dfb0b162d0000e1
    :100a3a0000003e30ce0097232130fc007630fd00c6
    :0e0a4a00fd0b252dfc0b252d0000e32c2b2d84
    :100a840021308400113083120313f0003130b2009e
    :080a94000530b3003b2408000b
    :080a620049344e3446340034df
    :040a6a0030340034f0
    :080a6e004e3461344e340034b3
    :0e0a7600763461346c34753465343a340034af
    :04400e00d2200007b5
    :00000001ff
     
  14. Ian Rogers

    Member

    Dec 12, 2012
    158
    29
    Not on a pic16f877a you won't.... It hasn't got any ansel registers.... ADCON1 = 0x7;

    But that's not his problem... In ISIS he need to set MCLR pin otherwise it will not simulate...
     
  15. tshuck

    Well-Known Member

    Oct 18, 2012
    3,531
    675
    1.)Put it in code tags! (The button that looks like"#" above your post's edit box - it surrounds your code with [CODE ] and [/CODE ] tags, minus the added spaces, so your post doesn't make the page gigantic)

    2.) Phrase put some context in your posts - explain why you are posting it and what it is for.

    3.) How did you verify the LCD works?
     
  16. tshuck

    Well-Known Member

    Oct 18, 2012
    3,531
    675
    ... even with MCLR turned off in the configuration?

    So it will let you simulate without a clock, but a missing pull up breaks it?:confused::rolleyes:
     
  17. Alicp

    Thread Starter New Member

    Mar 12, 2014
    7
    0
    same problem no new
     
  18. Ian Rogers

    Member

    Dec 12, 2012
    158
    29
    MCLR is not configurable on the pic16f877a...

    The crystal is not simulated in ISIS....
     
    tshuck likes this.
  19. ericgibbs

    AAC Fanatic!

    Jan 29, 2010
    2,504
    380
    hi Alicp,
    My program is reporting 'check sum errors' for your program listing, sorry I cannot run it.
     
  20. Ian Rogers

    Member

    Dec 12, 2012
    158
    29
    The initial jump location is to 0x4D5 but the hex line throws a CRC error.

    The code tries to access 0x107 and 0x108... not valid...

    The code is also displaying a CONFIG WORD2 again not from this chip... I suspect you have the wrong processor selected in your IDE!!
     
    Last edited: Mar 12, 2014
Loading...