convert from 16F877 to 18F4550


Closed Thread
Results 1 to 5 of 5
  1. #1
    Join Date
    Feb 2010
    Posts
    17

    Default convert from 16F877 to 18F4550

    Hi,
    I made a simple 12 bit ADC using LTC1298 in SPI with 16f887 and works perfect. I tried the same setup same pins with a 18F4550 but won't work.
    the 16F887 code is:

    Code:
    '==========================MCU SETUP============================================  
    DEFINE OSC 20
    Include "modedefs.bas"
    CM1CON0 = 0
    CM2CON0 = 0
    ANSEL = 0 ' set ANx as analog 
    ANSELH = 0
    '============================I/O SETUP==========================================
    TRISA = %11111111
    TRISB = %00000001
    TRISC  = %00010000
    TRISD = 0
    TRISE = 0
    
    SDI VAR PORTC.4 
    SCL VAR PORTC.6
    CS VAR PORTC.7
    SDO VAR PORTC.5
    pot_v var word ' Current Pot Value
    SLCD VAR PORTD.7
    '===============================VARIABLES======================================
    MUX1 var bit 
    MUX2 var bit
    MUX3 var bit
    MUX4 var bit
    null var bit
    dummy var word 
    ADCVAL VAR WORD
    I VAR WORD'Numbe of samples taken
    
    '================================usuart========================================9+
      
    
    
    CLEAR
    '=============================================================================
    
      adcval=0
      mux1=1:mux2=1:mux3=0:mux4=1
    PAUSE 500
    loop:
    LCDOUT $FE,1
    PAUSE 50
    LCDOUT "PRO POT TESTER V1.0 " 
    
    
    
    gosub adc
     
    MAIN:
    gosub adc
    lcdout $fe,$D4
    LCDOUT "P VAL",DEC POT_V,"   ","I",DEC I,"   "
    GOTO MAIN
    
    '====================READ ADC===================================================
    ADC:
    CS=0
    SHIFTOUT SDO,SCL,5,[MUX1\1]
    SHIFTOUT SDO,SCL,5,[MUX2\1]
    SHIFTOUT SDO,SCL,5,[MUX3\1]
    SHIFTOUT SDO,SCL,5,[MUX4\1]
    SHIFTin SDI,SCL,6,[null\1]
    SHIFTin SDI,SCL,6,[adcval\12]
    cs=1
    dummy = adcval*2442
    pot_v =  div32 1000
    I=I+1
     RETURN
    '=============================================================================== 
    END
    the above code works good with the 16F887 then I tried this which is the same with the 18F4550:

    Code:
    '===========================CONFIGURATION=======================================
    
    'CONFIG   FOSC = HSPLL_HS,  PLLDIV = 5 , CPUDIV = OSC1_PLL2       
    'CONFIG   FCMEN = ON , PWRT = OFF,  BOR = ON,  VREGEN = ON , WDT = OFF,PBADEN = OFF 
    'CONFIG  CCP2MX = OFF, LPT1OSC = OFF , LVP=OFF, ICPRT = OFF,STVREN = OFF  
    
    
    '==========================MCU SETUP============================================  
    DEFINE OSC 48
    Include "modedefs.bas"
    
    
    TRISA = %11111111
    TRISB = %00000001
    TRISC  = %00010000
    TRISD = 0
    TRISE = 0
    ADCON1=15
    PORTD=0
    PORTE=0
    PORTC=0
    
     
    '=============================================================================== 
    '==============================BAUD SETUP=======================================
    N38 CON 16390'38.4K RS232 BAUD RATE FOR SERIAL COMMUNICATION WITH LCD  
    '==========================I/O SETUP============================================
    
    SLCD var PORTD.7'SERIAL OUTPUT TO THE LCD:PIN#25
    START VAR PORTA.2'START BUTTON:PIN#
    
    SDI VAR PORTC.4 
    SCL VAR PORTC.6
    CS VAR PORTC.7
    SDO VAR PORTC.5
    
    '===============================================================================
    '===================================VARIABLES===================================
    pot_v var word ' Current Pot Value
    ADCVAL VAR WORD'ADC VALUE 
    MAXVALUE VAR WORD' POT MAX VALUE-POT FIXED VALUE 
    MINVALUE VAR WORD' POT FIXED VALUE-POT MIN VALUE
    MUX1 var bit'ADC SETUP BIT1 
    MUX2 var bit'ADC SETUP BIT2 
    MUX3 var bit'ADC SETUP BIT3 
    MUX4 var bit'ADC SETUP BIT4 
    null var bit'ADC NULL BIT
    dummy var word'DUMMMMMMMMMY VARIABLE USED FOR CALCULATIONS 
    fixed_V VAR WORD 'Start up Pot Value
    PMIN VAR WORD 'POT MIN VALUE
    PMAX VAR WORD'POT MAX VALUE
    I VAR WORD'Number of samples taken
    CLEAR
    '==============================================================================
     PAUSE 1000
    SEROUT2 SLCD,N38,[$FE,$58]'CLEAR DISPLAY
    PAUSE 10
    '===============================================================================
    
       
    adcval=0 :
      mux1=1:mux2=1:mux3=0:mux4=1
    PAUSE 500
    loop:
    SEROUT2 SLCD,N38,[$FE,$47,1,1,"PRO POT TESTER V1.0"]'DISPLAY CHARACTHERS
    
    MAIN:                            
    
     gosub adc
    SEROUT2 SLCD,N38,[$FE,$47,1,4,"P VAL:",DEC POT_V,"/I:",DEC I,"   "]
    
    
    GOTO MAIN
    
    '====================READ ADC===================================================
    ADC:
    CS=0
    SHIFTOUT SDO,SCL,5,[MUX1\1]
    SHIFTOUT SDO,SCL,5,[MUX2\1]
    SHIFTOUT SDO,SCL,5,[MUX3\1]
    SHIFTOUT SDO,SCL,5,[MUX4\1]
    SHIFTin SDI,SCL,6,[null\1]
    SHIFTin SDI,SCL,6,[adcval\12]
    cs=1
    dummy = adcval*2442
    pot_v =  div32 1000
    I=I+1
     RETURN
    '===============================================================================   
    END


    but I'm not reading the ADC in the 18F4550. The only difference is the serial LCD but I tried with both but no luck. I guess is something to do with : DEFINE SHIFT_PAUSEUS 100 if so what the value supposed to be?

    in advance thanks for any help you can provide.

    Best regards,
    Joe

  2. #2
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default Re: convert from 16F877 to 18F4550

    ADCON1=15
    Turns the ADC off.
    Dave
    Always wear safety glasses while programming.

  3. #3
    Join Date
    Feb 2010
    Posts
    17


    Did you find this post helpful? Yes | No

    Default Re: convert from 16F877 to 18F4550

    ADC turned off because i'm using an external 12bit ADC with SPI using shiftin and shifout commands.
    Thanks for the replay.

  4. #4
    Join Date
    Oct 2004
    Posts
    440


    Did you find this post helpful? Yes | No

    Default Re: convert from 16F877 to 18F4550

    Joe

    Concerning:
    SDI VAR PORTC.4
    SDO VAR PORTC.5

    From the 18F4550 data sheet:
    Digital input RC5 and RC4 are only available as port pins
    when the USB module is disabled (UCON<3> = 0).

    Unlike other PORTC pins, RC4 and RC5 do not have
    TRISC bits associated with them. As digital ports, they
    can only function as digital inputs.


    Norm

  5. #5
    Join Date
    Oct 2004
    Posts
    440


    Did you find this post helpful? Yes | No

    Default Re: convert from 16F877 to 18F4550

    Joe

    Any luck with the conversion?


    Norm

Similar Threads

  1. Need to convert C to PBP
    By timmers in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 6th August 2012, 06:47
  2. How to convert binary to decimal?
    By Cabomba in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 13th October 2007, 01:27
  3. Convert Hex to Decimal
    By RONKON in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 9th May 2006, 01:01
  4. Convert to Decimal
    By mglazer in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 5th November 2005, 11:31

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts