How do I get 18f452 pin 10 set as digital input?


Closed Thread
Results 1 to 11 of 11

Hybrid View

  1. #1
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    all available solution are listed in ADCON1 section.(register 17-2) Since we don't know your whole analog and/or digital need...

    RE.2=AN7
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  2. #2
    jessey's Avatar
    jessey Guest


    Did you find this post helpful? Yes | No

    Default Here is all my settings

    Hi Steve,

    Sorry for not getting back to you sooner but I got real busy at work the last few days and just got some time to reply. Below is listed all my config, defines and tris settings. I read this in the data sheet for the 18f452 but I don't understand what I'm reading. Maybe if you have the time you could explain what I need to do.

    RE2/CS/AN7
    PORTE has three pins (RE0/RD/AN5, RE1/WR/AN6
    and RE2/CS/AN7) which are individually configurable
    as inputs or outputs. These pins have Schmitt Trigger
    input buffers.
    The PORTE pins become the I/O control inputs for the
    microprocessor port when bit PSPMODE (TRISE<4>) is
    set. In this mode, the user must make certain that the
    TRISE<2:0> bits are set and that the pins are configured
    as digital inputs. Also, ensure that ADCON1 is configured
    for digital I/O. In this mode, the input buffers are
    TTL.
    Register 4-1 shows the TRISE register which also
    controls the Parallel Slave Port operation.
    PORTE pins are multiplexed with analog inputs. When
    selected for analog input, these pins will read as ‘0’s.
    TRISE controls the direction of the RE pins, even when
    they are being used as analog inputs. The user must
    make sure to keep the pins configured as inputs when
    using them as analog inputs.

    Thanks
    jessey

    Code:
                             --------------                                
                             |   18F452   |                                
            MCLR/Vpp ------> |1         40| <-----> RB7/PGD                
             RA0/AN0 <-----> |2         39| <-----> RB6/PGC                
             RA1/AN1 <-----> |3         38| <-----> RB5/PGM                
       RA2/AN2/Vref- <-----> |4         37| <-----> RB4                    
       RA3/AN3/Vref+ <-----> |5         36| <-----> RB3/CCP2*              
           RA4/TOCK1 <-----> |6         35| <-----> RB2/INT2               
    RA5/AN5/SS/LVDIN <-----> |7         34| <-----> RB1/INT1               
          RE0/RD/AN5 <-----> |8         33| <-----> RB0/INT0               
          RE1/WR/AN6 <-----> |9         32| <-----  Vdd +                  
          RE2/CS/AN7 <-----> |10        31| <-----  Vss -                  
               + Vdd  -----> |11        30| <-----> RD7/PSP7               
               _ VSS  -----> |12        29| <-----> RD6/PSP6               
           OSC1/CLK1  -----> |13        28| <-----> RD5/PSP5               
       OSC2/CLKO/RA6 <------ |14        27| <-----> RD4/PSP4               
     RC0/T1OSO/TICK1 <-----> |15        26| <-----> RC7/RX/DT              
     RC1/T1OSI/CCP2* <-----> |16        25| <-----> RC6/TX/CK              
            RC2/CPP1 <-----> |17        24| <-----> RC5/SDO                
         RC3/SCK/SCL <-----> |18        23| <-----> RC4/SD1/SDA            
            RD0/PSP0 <-----> |19        22| <-----> RD3/PSP3               
            RD1/PSP1 <-----> |20        21| <-----> RD2/PSP2               
                             -------------- 
    
                             --------------                                
                             |   18F452   |                                
                        MCLR |1         40| Water_Valve_1                  
                      Buzzer |2         39| Water_Valve_2                  
              Up_Push_Button |3         38| Water_Valve_3                  
            Down_Push_Button |4         37| Water_Valve_4                  
    Instructions_Push_Button |5         36| Water_Valve_5                  
         Select2_Push_Button |6         35| Water_Valve_6                  
          Select_Push_Button |7         34| The_Main_Water_Valve           
                         Lcd |8         33| The_Nutrient_Pump              
                         Lcd |9         32| <-----  Vdd +                  
     Need Digital Input here |10        31| <-----  Vss -                  
               + Vdd  -----> |11        30| Lcd                            
               - VSS  -----> |12        29| Lcd                            
                        OSC1 |13        28| Lcd                            
                        OSC2 |14        27| Lcd                            
       Communications_Port_1 |15        26| Nutrient_Valve_1               
       Communications_Port_2 |16        25| Nutrient_Valve_2               
       Communications_Port_3 |17        24| Nutrient_Valve_3               
       Communications_Port_4 |18        23| Nutrient_Valve_4               
       Communications_Port_5 |19        22| Nutrient_Valve_5               
       Communications_Port_6 |20        21| Nutrient_Valve_6               
                             --------------   
    
    '-------------------- PORTA PINS --------------------'
     TRISA.0 = 0 '(pin 2) ................ Buzzer       
     TRISA.1 = 1 '(pin 3) ................ Up_Push_Button     
     TRISA.2 = 1 '(pin 4) ................ Down_Push_Button      
     TRISA.3 = 1 '(pin 5) ................ Instructions_Push_Button  
     TRISA.4 = 1 '(pin 6) ................ Select2_Push_Button      
     TRISA.5 = 1 '(pin 7) ................ Select_Push_Button    
     
    '-------------------- PORTB PINS --------------------'
     
     TRISB.0 = 0 '(pin 33) ............... The_Nutrient_Pump      
     TRISB.1 = 0 '(pin 34) ............... The_Main_Water_Valve       
     TRISB.2 = 0 '(pin 35) ............... Water_Valve_6        
     TRISB.3 = 0 '(pin 36) ............... Water_Valve_5      
     TRISB.4 = 0 '(pin 37) ............... Water_Valve_4     
     TRISB.5 = 0 '(pin 38) ............... Water_Valve_3        
     TRISB.6 = 0 '(pin 39) ............... Water_Valve_2     
     TRISB.7 = 0 '(pin 40) ............... Water_Valve_1     
     
    '-------------------- PORTC PINS --------------------'
     TRISC.0 = 1 '(pin 15) ............... Communications_Port_1    
     TRISC.1 = 1 '(pin 16) ............... Communications_Port_2    
     TRISC.2 = 1 '(pin 17) ............... Communications_Port_3     
     TRISC.3 = 1 '(pin 18) ............... Communications_Port_4      
     TRISC.4 = 0 '(pin 23) ............... Nutrient_Valve_4     
     TRISC.5 = 0 '(pin 24) ............... Nutrient_Valve_3      
     TRISC.6 = 0 '(pin 25) ............... Nutrient_Valve_2    
     TRISC.7 = 0 '(pin 26) ............... Nutrient_Valve_1      
     
    '-------------------- PORTD PINS --------------------'
     
     TRISD.0 = 1 '(pin 19) ............... Communications_Port_5      
     TRISD.1 = 1 '(pin 20) ............... Communications_Port_6        
     TRISD.2 = 0 '(pin 21) ............... Nutrient_Valve_6       
     TRISD.3 = 0 '(pin 22) ............... Nutrient_Valve_5        
     TRISD.4 = 0 '(pin 27) ............... Lcd Data bit 4 
     TRISD.5 = 0 '(pin 28) ............... Lcd Data bit 5 
     TRISD.6 = 0 '(pin 29) ............... Lcd Data bit 6  
     TRISD.7 = 0 '(pin 30) ............... Lcd Data bit 7 
     
    '-------------------- PORTE PINS --------------------'
     
     TRISE.0 = 0 '(pin 8)  ............... Lcd Register select 
     TRISE.1 = 0 '(pin 9)  ............... Lcd Enable 
     TRISE.2 = 1 '(pin 10) ............... Need Digital Input here    
    
     @ __CONFIG _CONFIG1H, _OSCS_ON_1H & _XT_OSC_1H  
     @ __CONFIG _CONFIG2L, _BOR_OFF_2L & _BORV_20_2L & _PWRT_ON_2L
     @ __CONFIG _CONFIG2H, _WDT_ON_2H & _WDTPS_128_2H
     @ __CONFIG _CONFIG3H, _CCP2MX_OFF_3H
     @ __CONFIG _CONFIG4L, _STVR_OFF_4L & _LVP_OFF_4L & _DEBUG_OFF_4L
     @ __CONFIG _CONFIG5L, _CP0_OFF_5L & _CP1_OFF_5L & _CP2_OFF_5L & _CP3_OFF_5L
     @ __CONFIG _CONFIG5H, _CPB_OFF_5H & _CPD_OFF_5H
     @ __CONFIG _CONFIG6L, _WRT0_OFF_6L & _WRT1_OFF_6L & _WRT2_OFF_6L & _WRT3_OFF_6L 
     @ __CONFIG _CONFIG6H, _WRTC_OFF_6H & _WRTB_OFF_6H & _WRTD_ON_6H 
     @ __CONFIG _CONFIG7L, _EBTR0_OFF_7L & _EBTR1_OFF_7L & _EBTR2_OFF_7L & _EBTR3_OFF_7L
     @ __CONFIG _CONFIG7H, _EBTRB_OFF_7H
    
     DEFINE OSC 4     
     Define LCD_DREG   PORTD
     Define LCD_DBIT   4
     Define LCD_RSREG  PORTE
     Define LCD_RSBIT  0
     Define LCD_EREG   PORTE
     Define LCD_EBIT   1 
    
     ADCON1 = 7   ' Sets portA & E outputs to Digital 
    
    '-------------------------------------------'
    '----------- Configure Port Pins -----------'
    '-------------------------------------------'     
     Up_Push_Button VAR PORTA.1           '(pin 3)  
     Down_Push_Button VAR PORTA.2         '(pin 4)   
     Instructions_Push_Button VAR PORTA.3 '(pin 5)   
     Select_Push_Button VAR PORTA.5       '(pin 7) 
     Select2_Push_Button VAR PORTA.4      '(pin 6)    
     Buzzer VAR PORTA.0                   '(pin 2) 
     Need Digital Input Here VAR PORTE.1  '(pin 10) 
     The_Nutrient_Pump VAR PORTB.0        '(pin 33)   
     The_Main_Water_Valve VAR PORTB.1     '(pin 34)
     Water_Valve_1 VAR PORTB.7            '(pin 40)     
     Water_Valve_2 VAR PORTB.6            '(pin 39)
     Water_Valve_3 VAR PORTB.5            '(pin 38)
     Water_Valve_4 VAR PORTB.4            '(pin 37)
     Water_Valve_5 VAR PORTB.3            '(pin 36) 
     Water_Valve_6 VAR PORTB.2            '(pin 35)         
     Communications_Port_1 VAR PORTC.0    '(pin 15) 
     Communications_Port_2 VAR PORTC.1    '(pin 16) 
     Communications_Port_3 VAR PORTC.2    '(pin 17)  
     Communications_Port_4 VAR PORTC.3    '(pin 18)
     Communications_Port_5 VAR PORTD.0    '(pin 19)    
     Communications_Port_6 VAR PORTD.1    '(pin 20)
     Nutrient_Valve_1 VAR PORTC.7         '(pin 26) 
     Nutrient_Valve_2 VAR PORTC.6         '(pin 25)
     Nutrient_Valve_3 VAR PORTC.5         '(pin 24) 
     Nutrient_Valve_4 VAR PORTC.4         '(pin 23) 
     Nutrient_Valve_5 VAR PORTD.3         '(pin 22)
     Nutrient_Valve_6 VAR PORTD.2         '(pin 21)
    
     INCLUDE "EE_Vars.PBP"

  3. #3
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    so basically you need everything digital right?

    ADCON1=7
    and for safety sake
    SSPCON1=0

    this have to do the trick.. if not, you have a faulty PIC, faulty hardware.. or i need another drink ... 5:00 AM Here... still trying to forget those beauties that Lerameur bring to the night club tonight... mmmmmm

    Code:
    INCLUDE "EE_Vars.PBP"
    once you're done, please post some of your code that show/use that nice feature... at very least for others forum member benefit.. and Darrel's pleasure.
    Last edited by mister_e; - 12th May 2007 at 10:06.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  4. #4
    jessey's Avatar
    jessey Guest


    Did you find this post helpful? Yes | No

    Default Thanks Steve

    Hi Steve,

    That's great Steve, thanks for the code, I really appericate it. I'm off to work now (Saturday), I've worked every day this week and now the weekend!!.... Oh well. I'll be sure to post my code after I get a chance to try your suggestion and clean it up a bit. Give me a couple of days.

    Thanks Again
    jessey

  5. #5
    Join Date
    Apr 2006
    Location
    New Hampshire USA
    Posts
    298


    Did you find this post helpful? Yes | No

    Thumbs up neat coding style

    Hi jessey,
    Quote Originally Posted by jessey View Post
    Oh well. I'll be sure to post my code after I get a chance to try your suggestion and clean it up a bit. Give me a couple of days.
    I have to mention; Your coding style is quite easy to read and contains a lot of helpful information. So even though you are fairly new to PICs you code style is extremely helpful to us beginners. I am learning from it, and looking forward to your code posting.
    Thanks,
    -Adam-
    Ohm it's not just a good idea... it's the LAW !

  6. #6
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    well commented/documented code is indeed the trick. Well done!
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  7. #7
    jessey's Avatar
    jessey Guest


    Did you find this post helpful? Yes | No

    Default Still can't get pin 10 configured properly?

    Quote Originally Posted by Pic_User View Post
    Hi jessey,
    looking forward to your code posting.
    Thanks,
    -Adam-
    Hello Steve & Adam,

    Sorry for taking so long to post my code but I've been pretty busy lately and it took a bit to go through the program and try and make the comments make sense. I just hope you can follow the flow of the program. If you have any questions then feel free to ask.

    This program might be a little hard to follow because of all the Dummy variables that I used, I'm not sure if I'm using them correctly or if there's a better way of doing it but using the Dummy var's has saved me a lot of code space and the program seems to be working perfectly. Without them I definitely wouldn't have enough code space on my 18f452 for all the features I want to implement. There is still a lot I can do to save code space but its still a work in progress, I still have timing issues to resolve as well. Any comments or suggestions from anyone will be very much appreciated especially when it comes to using the Dummy variables.

    I didn't have time to go through Darrels Strings routine to comment it properly but I can say it works great. When I get all the features in my program that I want then I'll finish the Strings by including an overview of the programs features and instructions on how to set it up. Its great to have a manual programmed into the chip, better than written instructions because you can't loose them. In Darrels Strings I can get 142 prints in GetInstructions1 alone, plus probably well over 100 in the other GetInstructions ones that I'm using. That's a great routine Darrel and I thank you again for it.

    Oh, Steve I tried using SSPCON1=1 and I still can't seem to get pin 10 working as either a digital input or output. I tried it on a couple of different 452's with the same results?

    Thanks
    jessey
    Attached Files Attached Files

  8. #8
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by jessey View Post
    Oh, Steve I tried using SSPCON1=1 and I still can't seem to get pin 10 working as either a digital input or output. I tried it on a couple of different 452's with the same results?
    Thanks
    jessey
    Very well commented code indeed...BUT...the code, as a whole, looks entirely too over-written, over-designed, over-complicated, for the end result. This almost looks like something written for the Space Shuttle or something

    At any rate, back to the PortE.2 thing...
    Back to the basics is all I can say. Get a fresh breadboard, get a fresh PIC, a push button and an LED. Put the button on PortE.2 with a pullup (or a pulldown, whatever works), put the LED on another Port, whichever you want. Write a program that makes the LED follow the button's input, and ONLY the button's input...like:

    button var porte.2:input button:led var portb.0: output led:led=0

    main:
    if button = 1 then LED = 1
    if button = 0 then LED = 0
    goto main

    If that doesn't work right off the bat, then start playing with the config registers until things start working.

    I've read other posts from you, I know you've got a decent grasp on how to run these PICs. Sometimes a guy just forgets something stupid and silly and it kicks him in the arse for days...gotta break it back down to the basics.
    For all you know, the lead going to PortE.2 is open somewhere, or the switch itself is shot.

Similar Threads

  1. Is this a K Type sensor?
    By jessey in forum mel PIC BASIC Pro
    Replies: 20
    Last Post: - 21st November 2009, 13:55
  2. lumex 4 line display
    By glkosec in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 12th August 2009, 17:55
  3. 18f series chip locked up
    By glkosec in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 11th August 2009, 07:27
  4. Digital Out on an A/D pin safe ?
    By mr.sneezy in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 21st January 2009, 22:48
  5. 16f88 - pin RA4 as analog input
    By savnik in forum mel PIC BASIC Pro
    Replies: 20
    Last Post: - 15th December 2006, 13:55

Members who have read this thread : 0

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