Counting led blinks..


Closed Thread
Results 1 to 40 of 93

Hybrid View

  1. #1
    Join Date
    Jun 2011
    Location
    Philippines
    Posts
    223


    Did you find this post helpful? Yes | No

    Default Re: Counting led blinks..

    Hi added the following code to SDcard routines as suggested..
    Code:
    'SD CARD ROUTINES 
        SD_WRITE:
        CIU = 1
        SDINIT:
        ' FSInit initializes the card and reads all the preliminary information from it
        GOSUB FSInit
        IF (FAT_error != 0) THEN BLINK
    
    
        ' Display card directory
        GOSUB FINDfirst     ' Find first file on card
        WHILE (FAT_error = 0)
            GOSUB FINDnext  ' Find next file on card
        WEND
    
    
        BLINK:
        Toggle LED1
        Lcdout $fe, 1
        Lcdout $fe, 128,"I Blink"
        return
    My observation, when powered Rtc displays infos in the lcd after a couple second it goes to the BLINK routine and toggled the LED1 and displays "Blink". But after 6 seconds the lcd goes blank. BTW from the start of the program I can not connect to communication port its says "Serial port not available"
    This my SDCARD Connection:
    SCLK -> PortA.3
    MOSI -> PortA.5
    SD_CS -> PortC.2
    MISO -> PortC.1
    Name:  sdcard.jpg
Views: 1891
Size:  75.8 KB

    regards,
    tacbanon
    Last edited by tacbanon; - 24th October 2011 at 01:33.

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


    Did you find this post helpful? Yes | No

    Default Re: Counting led blinks..

    Do you have a data sheet for the SD card module?
    Dave
    Always wear safety glasses while programming.

  3. #3
    Join Date
    Jun 2011
    Location
    Philippines
    Posts
    223


    Did you find this post helpful? Yes | No

    Default Re: Counting led blinks..

    Hi, I don't have data sheet. I tried to search on www.lcsoft.net but there was none. But I was able to test this module successfully on a separate program using the following code.
    Code:
    asm   
         __CONFIG    _CONFIG1L, _PLLDIV_5_1L & _CPUDIV_OSC1_PLL2_1L & _USBDIV_2_1L 
         __CONFIG    _CONFIG2L, _PWRT_ON_2L & _BOR_ON_2L  & _BORV_2_2L  & _VREGEN_ON_2L   
        __CONFIG    _CONFIG2H, _WDT_OFF_2H 
        __CONFIG    _CONFIG3H, _MCLRE_ON_3H & _LPT1OSC_OFF_3H & _PBADEN_OFF_3H & _CCP2MX_ON_3H 
        __CONFIG    _CONFIG4L, _STVREN_ON_4L & _LVP_OFF_4L & _ICPRT_OFF_4L  & _XINST_OFF_4L & _DEBUG_OFF_4L 
    endasm
    DEFINE    OSC 48
    
    ' Alias PIC pins and registers for SD/MMC card
    SD_WE        Var    PORTA.4    ' SD card write protect
    SD_WE_TRIS    Var    TRISA.4    ' SD card write protect direction
    SDI        Var    PORTB.0    ' SPI data in
    SDI_TRIS    Var    TRISB.0    ' SPI data in direction
    SCL        Var    PORTB.1    ' SPI clock
    SCL_TRIS    Var    TRISB.1    ' SPI clock direction
    SD_CS        Var    PORTB.3    ' SD card chip select
    SD_CS_TRIS    Var    TRISB.3    ' SD card chip select direction
    SD_CD        Var    PORTB.4    ' SD card detect
    SD_CD_TRIS    Var    TRISB.4    ' SD card detect direction
    
    SDO        Var    PORTC.7    ' SPI data out
    SDO_TRIS    Var    TRISC.7    ' SPI data out direction
    
        Include "SDFS.PBP"
        SDC_UseHardSPI = TRUE    ' Use hardware SSP port for SPI.
    
        ADCON1 = 15        ' All I/O pins digital    Pause 100
    
        ' FSInit initializes the card and reads all the preliminary information from it
        Gosub FSInit
        Serout2 PORTC.6, 84, ["Init: ", Dec FAT_error, " ", Dec SDC_status, " ", Dec SDC_response, $d, $a]
        If (FAT_error != 0) Then Stop
    
        ' Display card directory
        Gosub FINDfirst        ' Find first file on card
        While (FAT_error = 0)
            Serout2 PORTC.6, 84, [Str FAT_FileName\11, $d, $a]
            Gosub FINDnext    ' Find next file on card
        Wend
    
    ' This section defines a specific short (8.3) filename
    '  Note that spaces are use in empty elements and must be upper case for Windows
        FAT_FileName[0] = "T"
        FAT_FileName[1] = "E"
        FAT_FileName[2] = "S"
        FAT_FileName[3] = "T"
        FAT_FileName[4] = "1"
        FAT_FileName[5] = " "
        FAT_FileName[6] = " "
        FAT_FileName[7] = " "
        FAT_FileName[8] = "T"
        FAT_FileName[9] = "X"
        FAT_FileName[10] = "T"
    
    ' Set file time to 8:30:10 and date to 1/1/2008
        FAT_seconds = 5
        FAT_minutes = 30
        FAT_hours = 8
        FAT_day = 1
        FAT_month = 1
        FAT_year = 28
    
    ' Open a file for write
        FAT_mode = "w"        ' Write mode
        Gosub FSfopen        ' Open file pointed to by Byte array FAT_FileName
        Serout2 PORTC.6, 84, ["Open for write: ", Dec FAT_error, $d, $a]
        If (FAT_error != 0) Then Stop
    
    ' Write to file
        FAT_src[0] = "P"
        FAT_src[1] = "r"
        FAT_src[2] = "0"
        FAT_src[3] = "t"
        FAT_src[4] = "o"
        FAT_src[5] = "t"
        FAT_src[6] = "y"
        FAT_src[7] = "p"
        FAT_src[8] = "e"
        FAT_count = 9
        Gosub FSfwrite
        Serout2 PORTC.6, 84, [ "Write ", Dec FAT_error, $d, $a]
        If (FAT_error != 0) Then Stop
    
    ' Close file
        Gosub FSfclose
        Serout2 PORTC.6, 84, [ "Close ", Dec FAT_error, $d, $a]
        If (FAT_error != 0) Then Stop
    
    ' Open a file for read
        FAT_mode = "r"        ' Read mode
        Gosub FSfopen        ' Open file pointed to by Byte array FAT_FileName
        Serout2 PORTC.6, 84, ["Open: ", Dec FAT_error, $d, $a]
        If (FAT_error != 0) Then Stop
    
    ' Read and display the whole file
        FAT_count = 1        ' Read 1 byte to buffer at a time
        Gosub FSfread
        While (FAT_error = 0)
            Serout2 PORTC.6, 84, [FAT_dest[0]]
            FAT_count = 1    ' Read 1 byte to buffer at a time
            Gosub FSfread
        Wend
        Serout2 PORTC.6, 84, [ "Read: ", Dec FAT_error, $d, $a]
        End
    regards,
    tacbanon
    Last edited by tacbanon; - 24th October 2011 at 23:45.

  4. #4
    Join Date
    Jun 2011
    Location
    Philippines
    Posts
    223


    Did you find this post helpful? Yes | No

    Default Re: Counting led blinks..

    Hi, I'm trying to test the RTC module on pic16F877A, according to the pins assignment SDA is on RC4 and SCL on RC3.
    Code:
    'RTC pins on 4550
    SDA    Var    PORTB.0
    SCL    Var    PORTB.1
    'The above code works
    Code:
    'RTC pins on 877a
    SDA    Var    PORTC.4
    SCL    Var    PORTC.3
    But this does not
    What do you think I'm missing?
    this is the code I'm using
    Code:
    DEFINE  OSC 20CLEAR
    
    
    ;----[LCD definitions]------------------------------------------------------
    DEFINE LCD_DREG PORTB
    DEFINE LCD_DBIT 0
    DEFINE LCD_EREG PORTB
    DEFINE LCD_EBIT 5
    DEFINE LCD_RSREG PORTB
    DEFINE LCD_RSBIT 4
    DEFINE LCD_BITS 4
    DEFINE LCD_LINES 2
    DEFINE LCD_COMMANDUS 2000
    DEFINE LCD_DATAUS 50
    'RTC pins on 877a
    SDA	Var	PORTC.4
    SCL	Var	PORTC.3
    
    
    ' Allocate variables
    RTCYear	Var	Byte
    RTCMonth Var Byte
    RTCDate	Var	Byte
    RTCDay	Var	Byte
    RTCHour	Var	Byte
    RTCMin	Var	Byte
    RTCSec	Var	Byte
    RTCCtrl Var	Byte
    
    
    TRISC= %11111111
    ;DB0 var byte[8]
    CMCON = %00000111                   ' Comparators = off
    
    
    ' Initialize LCD
    LCDOUT $FE,1:FLAGS=0:PAUSE 250:LCDOUT $FE,1:PAUSE 250 
    
    
    ' Set initial time 
    	RTCYear = $10
    	RTCMonth = $03
    	RTCDate = $23
    	RTCDay = $02
    	RTCHour = $19
    	RTCMin = $35
    	RTCSec = 0
    	RTCCtrl = 0
    	
    'Gosub set		' Set the time
    
    
    Goto mainloop		' Skip over subroutines
    
    
    ' Subroutine to write time to RTC
    set:
    	I2CWrite SDA,SCL,$D0,$00,[RTCSec,RTCMin,RTCHour,RTCDay,RTCDate,RTCMonth,RTCYear,RTCCtrl]
    	Return
    
    
    ' Subroutine to read time from RTC
    gettime:
    	I2CRead SDA,SCL,$D0,$00,[RTCSec,RTCMin,RTCHour,RTCDay,RTCDate,RTCMonth,RTCYear,RTCCtrl]
    	Return
    
    
    mainloop:
    	Gosub gettime		' Read the time from the RTC
    
    
        Lcdout $fe, 128,"Date:",  hex2 RTCDate, "/",hex2 RTCMonth, "/" , hex2 RTCYear
    	Lcdout $fe, $c0, "Time:", hex2 RTCHour, ":", hex2 RTCMin, ":", hex2 RTCSec
    
    
    	Pause 500
    Code:
    	Goto mainloop


    regards,
    tacbanon

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


    Did you find this post helpful? Yes | No

    Default Re: Counting led blinks..

    My guess is to try it on pins that are not Schmitt triggered.
    Dave
    Always wear safety glasses while programming.

  6. #6
    Join Date
    Jun 2011
    Location
    Philippines
    Posts
    223


    Did you find this post helpful? Yes | No

    Default Re: Counting led blinks..

    Hi mackrackit, I was able to run the RTC on PortB.0(SCL) and PortB.1(SDA). I'm still confused. I tried PortA ports that has TTL but did not work. and I have read other thread that they were able to run their program using Pic16F877A to read RTC module on PORTC.1 and PORTC.0 (Post# 1 http://www.picbasic.co.uk/forum/showthread.php?t=12671) can you help me point out how it works? I'm amazed that my lcd is also using PortB.0 and PortB.1 at the same time with the RTC required pins. BTW now I'm on Pic16F877A, does this mean that my sdcard module will not work on this chip?

    thanks for the patients,
    tacbanon



  7. #7
    Join Date
    Jun 2011
    Location
    Philippines
    Posts
    223


    Did you find this post helpful? Yes | No

    Default Re: Counting led blinks..

    oops sorry for the typos(patients) what I meant is patience

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