Could I have some advice on Which Pic Please?


Results 1 to 15 of 15

Threaded View

  1. #10
    Join Date
    Mar 2008
    Posts
    79


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by skimask View Post
    You know what else might be even easier would be to post the code and see if any of us could possibly help you optimize it a bit more and make it take up less code space
    Sorry didn't do it b4 as I didn't want to ask for too much help.
    JUST changed the code to get rid up unneeded pins, i.e led o/p's that wont be on the final version it will only use the lcd
    What I'd like to do more neatly is have it so if PORTD.1 is pressed twice within the space of 2 seconds the program jumps to STOP1
    If PORTD.1 is ONLY pressed once then it jumps to PURGING:
    I'm sure there is a simpler way to do it than I've used.

    Oh Acetronics thanks I've actually deleted quite a few lines of code and actually have no idea what size it assembles to at the moment as the computer I'm using at the moment doesn't have a complier on it
    BUT when I compiled the code that you saw, the hex file was 8K (7.28K to be exact)
    Maybe I did things wrong, I dont know i'm still extremely new to this, I was using the Mikroe easypic5 when i designed the circuit, now I've got rid of that and am going to make up a circuit board with just the parts needed and program it direct using the ICD2 (hopefully )

    Code:
    '****************************************************************
    '*  Name    : Oil Control.BAS                                      *
    '*  Author  : [select VIEW...EDITOR OPTIONS]                    *
    '*  Notice  : Copyright (c) 2008 [KarenH] *
    '*          : All Rights Reserved                               *
    '*  Date    : 06/05/2008                                        *
    '*  Version : 1.0                                               *
    '*  Notes   :                                                   *
    '*          :                                                   *
    '****************************************************************
                  Define	LOADER_USED	1
    
    @   DEVICE pic16F877a,HS_OSC,WDT_OFF,LVP_OFF                   
    ' Define various stuff
      DEFINE OSC 8
      DEFINE LCD_DREG PORTB       ' Set LCD Data port
            DEFINE LCD_DBIT 0           ' Set starting Data bit (0 or 4) if 4-bit bus .7
            DEFINE LCD_RSREG PORTB      ' Set LCD Register Select port
            DEFINE LCD_RSBIT 4          ' Set LCD Register Select bit 
            DEFINE LCD_EREG PORTB       ' Set LCD Enable port
            DEFINE LCD_EBIT 5           ' Set LCD Enable bit i.e, PORTE.4
            DEFINE LCD_BITS 4           ' Set LCD bus size ot 4 bit Upper Nibble (4 or 8 bits)
            DEFINE LCD_LINES 2         ' Set number of lines on LCD to 4 Lines
            DEFINE LCD_COMMANDUS 2000   ' Set command delay time in us
            DEFINE LCD_DATAUS 50        ' Set data delay time in us
                    
    
    
    ' Allocate variables
    command var     byte            ' Storage for command
    i       var     byte            ' Storage for loop counter
    temp    var     word            ' Storage for temperature
    DQ      var     PORTA.5         ' Alias DS1820 data pin
    DQ_DIR  var     TRISA.5         ' Alias DS1820 data direction pin
    
    
            ADCON1 = 7              ' Set PORTA and PORTE to digital
    
            Pause 500               ' Wait for LCD to start
            Lcdout $FE,1,"  All Circuits", $FE,$C0, " Funtioning  OK "      ' Display sign-on message
            Pause 3000              'Wait 3 seconds going any further
           
         
    
    ' Mainloop to read the temperature and display on LCD
    
      mainloop:
          
            Gosub init1820          ' Init the DS1820
    
            command = $cc           ' Issue Skip ROM command
            Gosub write1820
    
            command = $44           ' Start temperature conversion
            Gosub write1820
    
            Pause 500              ' Wait 0.5 seconds for conversion to complete
    
            Gosub init1820          ' Do another init
    
            command = $cc           ' Issue Skip ROM command
            Gosub write1820
    
            command = $be           ' Read the temperature
            Gosub write1820
            Gosub read1820
    
            ' Display the decimal temperature
          
           IF PORTC.0 = 0 AND PORTC.3 = 0 then lcdout $FE,1,"     Diesel", $FE,$C0,"Outside ", $fe, $C9, dec (temp >> 1), ".", dec (temp.0 * 5), $DF, "C":  LOW PORTE.0: LOW PORTE.1 
           IF PORTC.0 = 1 AND PORTC.3 = 0 then gosub Tempcheck
           IF PORTC.0 = 0 AND PORTC.3 = 1 then gosub Tempcheck
           If PORTC.0 = 1 AND PORTC.3 = 1 then gosub Oil
           IF PORTD.1 = 1 Then GOSUB purging
            
           
    Goto mainloop           ' Do it forever
    
      Stop1:
    
    LOW PORTE.0
    LOW PORTE.1
    LCDOUT $FE,1,"     MANUAL",$FE,$C0," Diesel OVERRIDE" 
    while PORTD.1=0           'OVERRIDE COMMAND to MANUALLY switch back to DIESEL i.e. if veg oil runs out
    wend
    pause 1000                 'so a very quick button press is NOT recognised and the program stays paused
    Goto Tempcheck 
    
      OIL:
    LCDOUT $FE,1,"     Veg-Oil", $FE,$C0,"Outside", $fe, $C9, dec (temp >> 1), ".", dec (temp.0 * 5), $DF, "C"
    HIGH PORTE.0          'Diesel Solenoid
    HIGH PORTE.1          'OIL Solenoid
    return 
    
    
    
      Tempcheck:
    lcdout $FE,1,"    TEMP LOW", $FE,$C0,"Still on  DIESEL"
    LOW PORTE.0: LOW PORTE.1   
     return
     
      Purging:
    
    LCDOUT $FE,1," PURGING Please",$FE,$C0,"      WAIT"
    HIGH PORTE.0     'Diesel Solenoid
    LOW PORTE.1      'Oil Solenoid
    Pause 60000          'set delay of purge here 60 seconds
             gosub Stop1 
    
    Goto mainloop
      
    
    ' Initialize DS1820 and check for presence
    init1820:
            Low DQ                  ' Set the data pin low to init
            Pauseus 500             ' Wait > 500us
            DQ_DIR = 1              ' Release data pin (set to input for high)
    
            Pauseus 100             ' Wait > 100us
            If DQ = 1 Then
                    Lcdout $fe, 1, "DS1820 not present"
                    Pause 500
                    Goto mainloop   ' Try again
            Endif
            Pauseus 400             ' Wait for end of presence pulse
            Return
    
    
    ' Write "command" byte to the DS1820
    write1820:
            For i = 1 to 8          ' 8 bits to a byte
                    If command.0 = 0 Then
                            Gosub write0    ' Write a 0 bit
                    Else
                            Gosub write1    ' Write a 1 bit
                    Endif
                    command = command >> 1  ' Shift to next bit
            Next i
            Return
    
    ' Write a 0 bit to the DS1820
    write0:
            Low DQ
            Pauseus 60              ' Low for > 60us for 0
            DQ_DIR = 1              ' Release data pin (set to input for high)
            Return
    
    ' Write a 1 bit to the DS1820
    write1:
            Low DQ                  ' Low for < 15us for 1
    @       nop                     ' Delay 1us at 4MHz
            DQ_DIR = 1              ' Release data pin (set to input for high)
            Pauseus 60              ' Use up rest of time slot
            Return
    
    
    ' Read temperature from the DS1820
    read1820:
            For i = 1 to 16         ' 16 bits to a word
                    temp = temp >> 1        ' Shift down bits
                    Gosub readbit   ' Get the bit to the top of temp
            Next i
            Return
    
    ' Read a bit from the DS1820
    readbit:
            temp.15 = 1             ' Preset read bit to 1
            Low DQ                  ' Start the time slot
    @       nop                     ' Delay 1us at 4MHz
            DQ_DIR = 1              ' Release data pin (set to input for high)
            If DQ = 0 Then
                    temp.15 = 0     ' Set bit to 0
            Endif
            Pauseus 60              ' Wait out rest of time slot
            Return
    
            End
    Last edited by karenhornby; - 16th May 2008 at 10:01.

Similar Threads

  1. SMS via pic
    By kenandere in forum GSM
    Replies: 15
    Last Post: - 10th March 2010, 10:00
  2. newbe looking for PIC advice
    By Mad Professor in forum General
    Replies: 3
    Last Post: - 27th May 2009, 07:56
  3. Midi, Interrupts and Pic better than SX28?
    By Lajko in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 27th September 2008, 00:26
  4. pic to pic ir link versus wired link : help please anyone
    By xnihilo in forum mel PIC BASIC Pro
    Replies: 13
    Last Post: - 30th May 2008, 21:01
  5. Serial Pic to Pic using HSER
    By Chadhammer in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 11th March 2005, 23:14

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