Counting led blinks..


Closed Thread
Results 1 to 40 of 93

Hybrid View

  1. #1
    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..

    Ok, now we know your USB hardware is working. Have you been able to write anything to the SD card? Try a small SD card program without USB to make sure the SD card stuff works.
    Dave
    Always wear safety glasses while programming.

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


    Did you find this post helpful? Yes | No

    Default Re: Counting led blinks..

    Hi, thanks for the responce. I successfully run this sample sd program.
    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
    ' Name        : sdfs3.pbp
    ' Compiler    : PICBASIC PRO Compiler 2.6 (PBPL only)
    ' Assembler   : MPASM
    ' Target PIC  : PIC16F4550
    ' Hardware    : Schematic available in http://melabs.com/resources/samples/pbp/sdfs3.zip
    ' Oscillator  : 20MHz
    ' Keywords    : SD Card, SD/MMC, FAT16
    ' Description : 10/02/08 - PICBASIC PRO 2.50L test program to talk to FAT16 
    ' formatted MMC/SD cards with PIC18F4550.  This is only a test program that 
    ' is part of a larger project.  The complete fileset with schematic, includes, 
    ' and details can be found at download: 
    ' http://melabs.com/resources/samples/pbp/sdfs3.zip
    
    
    
    
    ' 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 the SD/MMC subroutines (found in http://melabs.com/resources/samples/pbp/sdfs3.zip)
        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] = "A"
        FAT_src[1] = "B"
        FAT_src[2] = "C"
        FAT_count = 3
        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
    I also have my rtc module available. but at this time I do know how to use your code or connect it the developmemt board.

    regards,
    tacbanon
    Attached Images Attached Images  
    Last edited by tacbanon; - 12th October 2011 at 14:21.

  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 was able to test my RTC from this thread http://www.picbasic.co.uk/forum/showthread.php?t=12918...so far so good

    regards,
    tacbanon
    Attached Images Attached Images  

  4. #4
    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..

    COOL!!!!!

    The next piece of the puzzle is to get familiar with DT's instant interrupts. If you have not already done so.
    The short USB example earlier will need to be re-written to use DT's instants in place of the USB service include.

    Then put all of the pieces together. Modular type programming....
    Dave
    Always wear safety glasses while programming.

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


    Did you find this post helpful? Yes | No

    Default Re: Counting led blinks..

    Hi, sorry this question is related to previous post #27...I need to to send a character "c"(dec 99) constantly to the pc in the main loop(loop1). Then send 1(dec 49) if any coin pulse is detected.
    Code:
    ' Main Program LoopLoop1:
    'Lcdout $fe, 128, "Counter: ", #i 
    USBService ' Must service USB regularly
    '**************ADDED COde
     Buffer2[0] = 99  
     Buffer2[1] =13  
     TMR0L = 0     
     USBOut 3, Buffer2, cnt,Loop1
     goto Loop1
    '****************************
    TMR0L = 0     ' Clear TMR0 count before start
    
    Loop2:
        USBService
        WHILE TMR0L = 0 ' Wait for high-to-low transition 
        USBService       
        WEND           ' on RA4/T0CKI
        pause 5
        PORTB.0 = 1    ' LED on to indicate transition seen 
        i=i+1       ' Clear screen
        USBService
        buffer[0] = 49
        Buffer[1] = 13       
        USBOut 3, Buffer, cnt,Loop2
        'Lcdout $fe, 128, "Counter: ", #i   
        'PAUSE 30
        PORTB.0 = 0    ' LED off
        goto Loop1
    When I run the program..it displays "c" to the pc but never detect pulse when coin is dropped. Can you help me out what I'm doing wrong?

    thanks,
    tacbanon


  6. #6
    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..

    Post the whole code.
    Dave
    Always wear safety glasses while programming.

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


    Did you find this post helpful? Yes | No

    Default Re: Counting led blinks..

    Hi, here is the code...
    Code:
    ' Name        : Coin_Internet_CDC.pbp
    ' Compiler    : PICBASIC PRO Compiler 2.6
    ' Assembler   : PM or MPASM
    ' Target PIC  : PIC18F4550 
    ' Hardware    : Easypic6 Experimenter Board
    ' Oscillator  : 4MHz external crystal (only???)
    ' Thanks      :  To Henrik, and other PBP experts 
    ' Description : PICBASIC PRO program to show virtual serial comm. Working
    
    
    asm
       __CONFIG    _CONFIG1L, _PLLDIV_1_1L & _CPUDIV_OSC1_PLL2_1L & _USBDIV_2_1L   
        __CONFIG    _CONFIG1H, _FOSC_HSPLL_HS_1H & _FCMEN_OFF_1H & _IESO_OFF_1H
        __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
    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
    PAUSE 100 
    Include    "cdc_desc.bas"    ' Include the HID descriptors  
    Buffer    VAR BYTE[10]
    Buffer2    VAR BYTE[10]
    Cnt       VAR BYTE
    
    i    var byte
    
    INTCON2.7 = 0        ' Enable PORTB pull-ups
    TRISB = 110000          ' Enable all buttons
    ADCON1 = 15               ' Set all I/Os to Digital      
    
    
    CMCON = 7                 ' Disable Comparators
    Cnt = 3
    '****************************************************
    TRISA.4 = 1 ' RA4/T0CKI = input to TMR0 counter
    TRISA.0 = 0 ' RA0 = output for LED
    CMCON = 7   ' All digital 
    ADCON1 = 001111      ' A/D converter off
    
    
    'If you prefer, then increment on low-to-high transitions
    T0CON   = 111000       
    
    
    '*****************************************************
    
    
    USBInit                   ' Initialize USART
    
    
    ' Main Program Loop
    Loop1:
    Lcdout $fe, 128, "Counter: ", #i 
    USBService ' Must service USB regularly
    '**************ADDED COde
    Buffer2[0] = 99  
    Buffer2[1] =13       
    USBOut 3, Buffer2, cnt,Loop1
     'goto Loop1
    '****************************
    TMR0L = 0     ' Clear TMR0 count before start 
    
    
    Loop2:
        USBService
        WHILE TMR0L = 0 ' Wait for high-to-low transition 
        USBService       
        WEND           ' on RA4/T0CKI
        pause 5
        PORTB.0 = 1    ' LED on to indicate transition seen 
        i=i+1       ' Clear screen
        USBService
        buffer[0] = 49
        Buffer[1] = 13       
        USBOut 3, Buffer, cnt,Loop2
    Lcdout $fe, 128, "Counter: ", #i   
        'PAUSE 30
        PORTB.0 = 0    ' LED off
        goto Loop1
    regards,
    tacbanon
    Last edited by mackrackit; - 16th October 2011 at 08:06.

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