12f675_fuse_about_to_blow!


Closed Thread
Results 1 to 40 of 929

Hybrid View

  1. #1
    Join Date
    Feb 2010
    Location
    I live in the UK
    Posts
    562


    Did you find this post helpful? Yes | No

    Default

    Code:
    ANSEL   = %00000000    'Disable analog select so ports work as digital i/o.
    CMCON0  = %00000111    'Disable analog comparators.
    TRISA   = %00100000    'Set PORTA.5 as INPUT.
    PORTA   = %00000000    'Set PORTA pins all low.
    TRISC   = %00000000    'Set PORTC as OUTPUT.
    PORTC   = %00000000    'Set PORTC pins all low.
    
    DEFINE LCD_DREG     PORTC    'PORTC.0 WILL CONNECT TO DB4, PORTC3 TO DB7
    DEFINE LCD_DBIT     0
    DEFINE LCD_RSREG    PORTC
    DEFINE LCD_RSBIT    4        'PORTC.4 CONNECT TO LCD PIN4
    DEFINE LCD_EREG     PORTC
    DEFINE LCD_EBIT     5        'PORTC.5 CONNECT TO LCD PIN6
    DEFINE LCD_BITS     4
    DEFINE LCD_LINES    4
    DEFINE LCD_COMMANDUS 2000     
    DEFINE LCD_DATAUS 150
    
    DEFINE OSC 4
    
    TOTAL  VAR WORD  'STORED IN EEPROM LOCATIONS 0 AND 1
    PS_1   VAR WORD  'STORED IN EEPRON LOCATIONS 2 AND 3
    PS_2   VAR WORD  'STORED IN EEPRON LOCATIONS 4 AND 5
    PS_3   VAR WORD  'STORED IN EEPRON LOCATIONS 6 AND 7
    PS_4   VAR WORD  'STORED IN EEPRON LOCATIONS 8 AND 9
    PS_5   VAR WORD  'STORED IN EEPRON LOCATIONS 10 AND 11
    M_S    VAR BYTE  'STORED IN EEPRON LOCATIONS 12 
    
    clear                 'Re_set volatile memory to zero (Not EEPROM?)
    
    MAIN:
    
    gosub MC_S            'Set & increment M/C Starts Total subroutine
    gosub Power_up        'On Power_up GOTO READ EEPROM subroutine
    gosub Parts_Run       'Number of parts made
    
    
    Start:
    if PORTA.5 = 0  then  count_up: 'If button pressed start counting
    IF PORTA.5 = 1  THEN     Start: 'If button not pressed loop until it is
        
    Count_up:                 'Button has been pressed
    let Total = Total + 1     'Add one to value of Total taken from EEPROM
    pause 100
    LCDOUT $FE,2,"Total=",DEC TOTAL  'Display Total on LCD
    Write 0, Total.HIGHBYTE   ' Write high byte of Total word to EEPROM
    Write 1, Total.LOWBYTE    ' Write low byte of Total word to next address
    GOTO sTART:
    
    MC_S:                     'MC Starts subroutine
    READ 12, M_s              'Read current number of M/C Starts
    LET M_S = M_S + 1         'Increment value by one
    WRITE 12, M_S             'Save new value
    READ 12, M_s              'Read latest value
    pause 150                 'Give LCD a chance to Power_up
    LET M_S = M_S             'Set value to display
    LCDOUT $FE,$C0, "Machine Starts=",DEC M_S 'Display M/C Starts on LCD from EEPROM
    RETURN
    
     
    Power_up:                 'Power_up subroutine
    Read 0, Total.HIGHBYTE	  ' Read high byte
    Read 1, Total.LOWBYTe     ' Read low byte  
    LET Total = Total         'Set Total to value set in EEPROM Memory
    pause 150                 'Give LCD a chance to Power_up
    LCDOUT $FE,2,"Total=",DEC Total 'At Power_up display Total on LCD from EEPROM
                              'Memory which has been stored since Power_down
    return 
    
    Parts_Run:
    SELECT CASE M_S 
       CASE 1
       if M_s = 1 then PARTS1: 
       CASE 2
       IF M_S = 2 THEN PARTS2:
       CASE 3
       IF M_S = 3 THEN PARTS3:
       CASE 4
       IF M_S = 4 THEN PARTS4:
       CASE 5
       IF M_S = 5 THEN PARTS5:
    END SELECT 
    RETURN
    
    PARTS1:
    let PS_1 = Total
    WRITE 2,PS_1.HIGHBYTE
    WRITE 3,PS_1.LOWBYTE
    READ  2,PS_1.HIGHBYTE
    READ  3,PS_1.LOWBYTE
    LET PS_1 = PS_1
    PAUSE 150
    LCDOUT $FE, $94,"Parts1=",DEC PS_1
    return
    
    
    PARTS2:
    LET PS_2 = Total - PS_1
    WRITE 4,PS_2.HIGHBYTE
    WRITE 5,PS_2.LOWBYTE
    READ  4,PS_2.HIGHBYTE
    READ  5,PS_2.LOWBYTE
    LET PS_2 = PS_2
    PAUSE 150
    LCDOUT $FE, $94,"Parts2=",DEC PS_2
    return
    
    
    PARTS3:
    LET PS_3 = TOTAL - PS_2
    WRITE 6,PS_3.HIGHBYTE
    WRITE 7,PS_3.LOWBYTE
    READ  6,PS_3.HIGHBYTE
    READ  7,PS_3.LOWBYTE
    LET PS_3 = PS_3
    PAUSE 150
    LCDOUT $FE, $94,"Parts3=",DEC PS_3
    return
    
    
    PARTS4:
    LET PS_4 = TOTAL - PS_3
    WRITE 8,PS_4.HIGHBYTE
    WRITE 9,PS_4.LOWBYTE
    READ  8,PS_4.HIGHBYTE
    READ  9,PS_4.LOWBYTE
    LET PS_4 = PS_4
    PAUSE 150
    LCDOUT $FE, $94,"Parts4=",DEC PS_4
    return
    
    
    PARTS5:
    LET PS_5 = TOTAL - PS_4
    WRITE 10,PS_5.HIGHBYTE
    WRITE 11,PS_5.LOWBYTE
    READ  10,PS_5.HIGHBYTE
    READ  11,PS_5.LOWBYTE
    LET PS_5 = PS_5
    PAUSE 150
    LCDOUT $FE, $94,"Parts5=",DEC PS_5
    return
    Last edited by LEDave; - 10th May 2010 at 17:09.

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


    Did you find this post helpful? Yes | No

    Default

    I am on a very small display right now so I might be missing something...

    It looks like having PS_1 and PS_2 and so on equaling TOTAL is the problem.
    The PS_X's should be independent of the TOTAL. If all of the PS_X's are added together then they will equal TOTAL.
    Dave
    Always wear safety glasses while programming.

  3. #3
    Join Date
    Feb 2010
    Location
    I live in the UK
    Posts
    562


    Did you find this post helpful? Yes | No

    Default

    Cheers mackrackit,

    It looks like having PS_1 and PS_2 and so on equaling TOTAL is the problem.
    The PS_X's should be independent of the TOTAL. If all of the PS_X's are added together then they will equal TOTAL.
    I'll have a think about that one and make some changes.

    Dave

  4. #4
    Join Date
    Feb 2010
    Location
    I live in the UK
    Posts
    562


    Did you find this post helpful? Yes | No

    Default

    Ok, I've got an idea to work on now (I was lost before). So each PS_1 - 2 - 3 etc, are all individual counting loops.So each time 'Total does one count it then enters PS_n so yo have one Total counter and five PS_n counters.

    I'm back on the scent now......

    Cheers mackrackit.

    Dave

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


    Did you find this post helpful? Yes | No

    Default

    In think you got it now.
    I made this up but you may not need it, sometimes even a "bad" flowchart helps.
    Name:  EPPROM_FLOW.jpg
Views: 953
Size:  102.4 KB
    Dave
    Always wear safety glasses while programming.

  6. #6
    Join Date
    Feb 2010
    Location
    I live in the UK
    Posts
    562


    Did you find this post helpful? Yes | No

    Default

    Brilliant flowchart mackrackit

    Yes over the last hurdle now (I think). I've got PS_1-5 counting their own totals. Small problem in that the counts started from one all the time, then I realised that the button condition could set the count which your flow chart confirmed

    All being well the 'Mission' will be completed tomorrow.

    Watch this space...

    Dave

  7. #7
    Join Date
    Feb 2010
    Location
    I live in the UK
    Posts
    562


    Did you find this post helpful? Yes | No

    Default

    One last question (I think).

    The very first time the M/C is started we want 'Total' to equal zero (after all nothing's been made yet) So how do I initialize EEPROM 'Total' to zero the first time the M/C runs?. The second time it starts it reads the stored value of 'Total' and adds to that.

    The reason I'm asking this is because every time I compile and run the program, there seems to be a value already stored on EEPROM 'Total'.

    Dave

  8. #8
    Join Date
    Feb 2006
    Location
    Gilroy, CA
    Posts
    1,530


    Did you find this post helpful? Yes | No

    Default

    Nice results! First try, I like that!

    I have not tested at night, but it might help to get your camera right up against the glass, and make a cardboard, or black paper "flash block" that would block some of the light coming from the flash from getting to the glass in front of the lens. As I say, I did not test at night, I just did a test out of a dark window this morning. It seems to be better, but night is the true test. I think if you get rid of some of the flash reflection, you will be better.

    But again, congrats on catching a badger the first try!

    Walter

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