Stuck on porting code to 18F4520


Closed Thread
Results 1 to 40 of 43

Hybrid View

  1. #1
    Join Date
    May 2013
    Location
    australia
    Posts
    2,705


    Did you find this post helpful? Yes | No

    Default Re: Stuck on porting code to 18F4520

    its all in the manual ,// is modulo and ! is not

    ss//7 =0 :- means if ss is divided by 7 it's the remainder that is tested to be equal to 0 , ie 15/7 = 2 with a remainder of 1 whereas 21//7 = 3 with a remainder of 0
    the != :- means simply not equal to

  2. #2
    Join Date
    Oct 2009
    Posts
    583


    Did you find this post helpful? Yes | No

    Default Re: Stuck on porting code to 18F4520

    Richard, I've stumbled on a small issue which I would like some further assistance with if possible.

    I have two channels, one for blue LEDs and the other for Whites. I've replicated the working CASE statements for the white, but I can't seem to find a solution to running these case statements independently. I need to be able to have the two channels working at different times, for example both the Blues and Whites come on at 14:00 hrs, the Whites ramp up at a different rate than the blues (as set by the //7 part of the code) and then whites fade down at 20:00 hrs, followed by the blues at 20:15.

    If I comment out the section under blue select the whites run fine, and vice-verca, but whilst the LCD displays a change in case (ie from NIGHT to DAWN) for both white and blue channels, only one (the blues) ramps up the LED and displays the increasing percentage on the LCD. Here's the code (now tidied up with the non used variables etc removed)

    Code:
    '*******************************************************************************
    ' Variables
    '*******************************************************************************
    
    DecButton var PORTA.0	         ' Press to Decrement Button
    SetButton var PORTA.1            ' Press to Set/memorise Button
    IncButton var PORTA.2	         ' Press to Increment Button
    
    H_butt   VAR PORTA.2
    M_butt   VAR PORTA.0
    S_butt   VAR PORTA.1
    
    Counter1 var word
    
    ' LED variables - Whites:
    W_Min           var word    'Min Light value
    W_Max           var word    'Max Light value
    
    ' LED variables - Blues:
    B_Min           var word    'Min Light value
    B_Max           var word    'Max Light value
    
    'PWM Variables where the current output values are stored
    W_PWM           var word    'Whites
    B_PWM           var word    'Royal Blues
    
    HzTimer VAR Word         '1/2 second counter (2 Hz)    
    HH VAR Byte  ' Hours 0-23
    MM VAR ByTE  ' Minutes 0-59
    SS VAR Byte  ' Seconds 0-59
    col VAR Byte  ' colon 1=on, 0=0ff
    
    old_ss var byte
    
    '*******************************************************************************
    Blue_Day_Cycle      var word    'Store for which part of the day cycle we are in
    White_Day_Cycle     var word
    
    ' Constants for the current running mode cycle for the lights
    DAWN    con     0
    DAY     con     1
    DUSK    con     2
    NIGHT   con     3
    
    '*******************************************************************************
    ;Initialization
    
    LCDOUT $FE,1:FLAGS=0:PAUSE 250:LCDOUT $FE,1:PAUSE 250 ' Initialize LCD
    LCDOUT  $FE,1
    lcdout  $FE,$C0,"    Version R    "
    pause   2000   'wait 2 seconds so they can see it
    lcdout  $FE,1   'Clear the screen
       
    HzTimer=$7A12        'for 1/2 Sec
    HH=19:MM=59:SS=50:col=0 'initial conditions (19:59 )
    
    B_MAX=255
    W_MAX=255
    
    '*******************************************************************************
    '************                       Main Program Loop              *************
    '*******************************************************************************
    Main:
    
    ClockLoop: IF intcon.2=0 THEN ClockLoop	'Poll for TMRO overflow
    INTCON.2=0 ' Clear TMRO overflow flag
    
    HzTimer=HzTimer-$1000	'decrement timer count
    
    IF HzTimer < $1000  THEN
    IF Col=10 THEN    ' update time'
    SS=SS+1
            
    IF SS=60 THEN   ' minute
    SS=0 
    MM=MM+1
    IF MM=60 THEN    ' hour            
    MM=0
    HH=HH+1
    IF HH=24 THEN HH=0
    ENDIF                           
    counter1 = (HH*60)+MM
    ENDIF
    ENDIF
    Col=Col+1
    
    HzTimer=HzTimer+$7A12	' Add 0.5 seconds to count
    ELSE
        ' Do something here but must be less than 65.5 mSec
    ENDIF
    if Col=11 then 
    Col=1
    endif
       
    LCDOut $FE,$D4,#HH DIG 1,#HH DIG 0,":",#MM DIG 1,#MM DIG 0,":",#SS DIG 1,#SS Dig 0 
    
    If Counter1 < 1200 then
    Blue_day_cycle = NIGHT
    endif
    
    if Counter1 = 1200 then
    Blue_day_cycle = DAWN
    endif
    
    If Counter1 < 1200 then
    White_day_cycle = NIGHT
    endif
    
    if Counter1 = 1200 then
    White_day_cycle = DAWN
    endif
    
    
    '*** Do BLUE daily cycle
    select case Blue_Day_Cycle
        
    case DAWN 
    lcdout $FE,$80+13,"DAWN "   
    if ss//1= 0 then
    if ss != old_ss then
    B_PWM=B_PWM+1
    old_ss=ss
    endif
    endif
    if B_PWM = b_max then
    Blue_Day_Cycle = DAY
    endif
    
    case DAY
    lcdout $FE,$80+13,"DAY  "
    if counter1 =1210 then
    Blue_day_cycle = DUSK
    endif
        
    CASE DUSK
    lcdout $FE,$80+13,"DUSK "
    if ss//1= 0 then
    if ss != old_ss then
    B_PWM=B_PWM-1
    old_ss=ss
    endif
    endif
    if B_PWM = b_min then 
    Blue_Day_Cycle = NIGHT
    endif
    
    case NIGHT
    lcdout $FE,$80+13,"NIGHT"
    B_PWM=B_min
    end select
    
    
    '*** Do WHITE daily cycle
    select case White_Day_Cycle
        
    case DAWN 
    lcdout $FE,$C0+13,"DAWN "   
    if ss//1= 0 then
    if ss != old_ss then
    W_PWM = W_PWM+1
    old_ss=ss
    endif
    endif
    if W_PWM = W_max then
    White_Day_Cycle = DAY
    endif
    
    case DAY
    lcdout $FE,$C0+13,"DAY  "
    if counter1 =1210 then
    White_day_cycle = DUSK
    endif
        
    CASE DUSK
    lcdout $FE,$C0+13,"DUSK "
    if ss//1= 0 then
    if ss != old_ss then
    W_PWM=W_PWM-1
    old_ss=ss
    endif
    endif
    if W_PWM = W_min then 
    White_Day_Cycle = NIGHT
    endif
    
    case NIGHT
    lcdout $FE,$C0+13,"NIGHT"
    W_PWM=W_min
    end select
    
        hpwm 1,W_PWM,200        
        hpwm 2,B_PWM,200
    
    If (B_PWM * 100)/255 = 100 then
    lcdout $FE,$80,"BLUES  ",dec3 (B_PWM *100)/255,"%"
    endif
    
    If (B_PWM * 100)/255 =0 or (B_PWM * 100)/255 <10 then
    lcdout $FE,$80,"BLUES  ",dec1 (B_PWM *100)/255,"% "
    endif
    
    if (B_PWM * 100)/255 >=10 and (B_PWM * 100)/255 <100 then
    lcdout $FE,$80,"BLUES  ",dec2 (B_PWM *100)/255,"%  "
    endif
    
    If (W_PWM*100)/255 >= 100 then
    lcdout $FE,$C0,"WHITES ",dec3 (W_PWM *100)/255,"%"
    endif
    
    If (W_PWM * 100)/255 <=0 or (W_PWM * 100)/255 <10 then
    lcdout $FE,$C0,"WHITES ",dec1 (W_PWM *100)/255,"% "
    endif
    
    if (W_PWM * 100)/255 >=10 AND (W_PWM * 100)/255 <100 then
    lcdout $FE,$C0,"WHITES ",dec2 (W_PWM *100)/255,"%  "
    endif
    
    'Get and display the temperature
    
        OWOUT DQ, 1, [$CC, $44]                 ' Start temperature conversion
        OWOUT DQ, 1, [$CC, $BE]                 ' Read the temperature
        OWIN DQ, 0, [temperature.LOWBYTE, temperature.HIGHBYTE]
        temperature = temperature */ 1600
        lcdout $FE,$D4+11,"TEMP ",DEC(temperature / 100),$DF,"C"
      
    GOTO Main 
    
    ''****************************************************************     
    ';************        Main Program Loop END          *************
    ''****************************************************************
    Any suggestions ?

Similar Threads

  1. Porting code to new PIC
    By malc-c in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 1st January 2011, 00:20
  2. Kind of stuck
    By gti_uk in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 31st May 2009, 21:45
  3. Getting Stuck in loop
    By Frozen001 in forum mel PIC BASIC Pro
    Replies: 22
    Last Post: - 19th November 2008, 16:46
  4. Any idea's on porting this to PBP?
    By Ryan7777 in forum mel PIC BASIC Pro
    Replies: 20
    Last Post: - 10th October 2008, 20:21
  5. Replies: 1
    Last Post: - 8th May 2008, 01:52

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