Stuck on porting code to 18F4520


Closed Thread
Results 1 to 40 of 43

Hybrid View

  1. #1
    Join Date
    Oct 2009
    Posts
    583


    Did you find this post helpful? Yes | No

    Default Re: Stuck on porting code to 18F4520

    Hi Henrik,

    I already had the LCD delays in place, but added an initial two second pause and clear before the main code. I now have the time displayed on the LCD using the following code

    Code:
    ASM 
      __CONFIG    _CONFIG1H, _OSC_HS_1H
      __CONFIG    _CONFIG2L, _PWRT_ON_2L  
      __CONFIG    _CONFIG2H, _WDT_ON_2H & _WDTPS_512_2H
      __CONFIG    _CONFIG3H, _MCLRE_ON_3H & _LPT1OSC_OFF_3H & _PBADEN_OFF_3H  
      __CONFIG    _CONFIG4L, _LVP_OFF_4L & _XINST_OFF_4L
    ENDASM
    
    DEFINE  OSC 20  ; 48 was old config settings 18F4520, 20mhz crystal
    ADCON1 = $0F
    clear
    
    
    DEFINE LCD_DREG  PORTB           ' LCD Data port
    DEFINE LCD_DBIT  0               ' starting Data bit (0 or 4)
    DEFINE LCD_EREG  PORTB           ' LCD Enable port
    DEFINE LCD_EBIT  5               '     Enable bit  (on EasyPIC 5 LCD)
    DEFINE LCD_RSREG PORTB           ' LCD Register Select port
    DEFINE LCD_RSBIT 4               '     Register Select bit   (on EasyPIC 5 LCD)
    DEFINE LCD_BITS  4               ' LCD bus size (4 or 8 bits)
    DEFINE LCD_LINES 4               ' number of lines on LCD
    DEFINE LCD_COMMANDUS 2000        ' Command delay time in us 
    DEFINE LCD_DATAUS 50             ' Data delay time in us 
    
    LED var portA.7
    
    
    
    CMCON=7                'all digital 
    T0CON = %11000111
    INTCON=0               'interrupts off
    '**********************************************************
    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
    
    HzTimer=$7A12        'for 1/2 Sec
    HH=12:MM=0:SS=0:col=0 'initial conditions (12:00 O'clock noon)
    '**********************************************************
    
    LCDOUT $FE,1:FLAGS=0:PAUSE 250:LCDOUT $FE,1:PAUSE 250 ' Initialize LCD 
    
    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
            LED =0    ' Turn off GP1
            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
                    IF HH=20 then LED = 1    ' Turn on GP0 at 8:00pm
                   LED =1    ' Turn On  GP1 for 1 second on the hour
                ENDIF                           ' Adjust these to meet your needs
                if MM=15 then LED = 0        ' Turn off GP0 at 8:15pm  
            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,":",#MM,":",#SS
        
    GOTO  Main 'forever
    ' **************************************************************
    END
    I changed one of the defines in the config as it was using the PLL option so setting this to just HS resolved the OSC setting.

    The display is crude and needs some tiding up to overdraw double digits (the 9 in 59 is left on the screen so when it counts 1,2,3 seconds it displays 19,29,39 etc) but I can work on that. I just hope I have enough time between the overflows to do the rest of the code, such as fade in LEDs over a period of time etc.

    Thanks for your help. - here's the code I'm now using which works on an 18F4520 with a 20mhz xtal



    Thanks once again for your help...

  2. #2
    Join Date
    Oct 2009
    Posts
    583


    Did you find this post helpful? Yes | No

    Default Re: Stuck on porting code to 18F4520

    Its been a long day....
    Code:
        IF HH = 20 and MM = 0 then 
        LED = 1  
        endif
        lcdout $FE,$80,#LED
    for some reason when the LCD displays 20:00:00 the LED value still remains 0 and the LED fails to light

    Time for bed... now even the simple stuff won't work !

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