Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] PIC18F4520 code decoding help needed

Status
Not open for further replies.

vinayakdabholkar

Advanced Member level 4
Full Member level 1
Joined
Nov 29, 2009
Messages
114
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,296
Location
goa
Visit site
Activity points
2,195
i have just made this simple code and dont seem to understand why its not working. When i put the hex file in proteus i dont get any output on port D
Code:
/* 
 * File:   LED.c

 *
 * Created on 13 March, 2013, 3:10 PM
 */
[ATTACH=CONFIG]88413._xfImport[/ATTACH]
#include <stdio.h>
#include <stdlib.h>
#include <pic18f4520.h>
#pragma config OSC=HS
#pragma config WDT=OFF
#pragma config LVP=OFF
#pragma config DEBUG=OFF
#pragma config MCLRE=OFF
#pragma config PBADEN = OFF 		//portB 0to 4 digital - not analogue
/*
 * 
 */
void ADCInt()
{
    ADCON2=0b10001010;
    ADCON1=0b00111011;
}
unsigned int ADCRead(unsigned char ch)
{
    if(ch>13)return 0;
    ADCON0bits.ADON=1;
    ADCON0bits.GO=1;
    while(ADCON0bits.DONE==1);
    ADCON0bits.ADON=0;
    return ADRESL;

}
  void main()
{
     char val;
      TRISAbits.RA0=1;
      TRISD=0x00;
      ADCInt();
     val=ADCRead(0);
      LATD=val;
      //LATDbits.LATD0=1;
}
 

How do you expect to see the result?
I want to see the output on port C and D. lower byte on Port D and higher byte on Port C
Is GO and DONE bits different?
No, GO and DONE is the same bit, corrected that.
where is while(1) loop?
Yes, the while loop was missing, incorporated that too.
Where is Comparator register configuration?
Turned off the comparator module
Have seen other codes on the net and they are also following the same logic and so i made it similar to them. The difference in those codes is that they are using internal references Vdd and Vss and i have just used analog references and connected 5V to positive reference and gnd to -Ve . So nothing different there too. But i still dont get any output on the ports. Finding mistakes in simple codes is very difficult , Please help me out here
This is my new code
Code:
unsigned int temp_res;
void ADCInit()
{
 CMCON =CMCON | 0x07;          // Disable comparators
// ADCON0= 0x00;                 // ADC off Channel 0
 ADCON1= 0x3B;
 ADCON2= 0x92;

 }

  unsigned int ADCRead(unsigned char ch)
  {
  ADCON0=0x00;
  if (ch>13) return 0;
  ADCON0= (ch<<2);
  ADON_bit=1;
  GO_DONE_bit=1;
  while(GO_DONE_bit);
  ADON_bit=0;
  return ADRES;
  }
  void main()
  {
  ADCInit();
  AN0_bit=1;
  TRISD=0x00;
  //PORTD=0x00;
  TRISC=0x00;
  //PORTC=0x00

  while(1)
  {
  unsigned int val;
  val=ADCRead(0);
  LATD=val;
  LATC=(val>>8);
  }
  }
This has been compiled in MikroC and it compiles well.

- - - Updated - - -

I have not used the inbuilt functions as they work for fixed configuration , like references can only be set as Vdd and Vss
http://www.mikroe.com/download/eng/documents/compilers/mikroc/pro/pic/help/adc_library.htm
 

Attachments

  • put.png
    put.png
    177.6 KB · Views: 84

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top