-
1 Attachment(s)
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
-
1 Attachment(s)
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
-
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....
-
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
-
Re: Counting led blinks..
-
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
-
Re: Counting led blinks..
I see missing % on these
ADCON1 = 001111
T0CON = 111000
And each one should have 8 bits.
Go back and look at post #19 of this thread.
-
Re: Counting led blinks..
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
b0 var byte
B1 VAR BYTE ' Working buffer 1 for button command
sel VAR BYTE ' Working buffer 2 for button command
B3 VAR BYTE ' Working buffer 3 for button command
i var byte
Clear ' Clear buffers
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 = 5
i = 0
'****************************************************
TRISA.4 = 1 ' RA4/T0CKI = input to TMR0 counter
TRISA.0 = 0 ' RA0 = output for LED
CMCON = 7 ' All digital
'If you prefer, then increment on low-to-high transitions
T0CON = %11111000
'*****************************************************
USBInit ' Initialize USART
' Main Program Loop
Loop1:
Lcdout $fe, 128, "Counter: ", #i
USBService ' Must service USB regularly
TMR0L = 0 ' Clear TMR0 count before start
'**************ADDED COde
'gosub usbtx
'****************************
'goto Loop1
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
Hi mackrackit, the above code works. Now what I'm trying to do is add a ntoher line of code to send "c" in the main loop but I can not seem to make it work.
Code:
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
b0 var byte
B1 VAR BYTE ' Working buffer 1 for button command
sel VAR BYTE ' Working buffer 2 for button command
B3 VAR BYTE ' Working buffer 3 for button command
i var byte
Clear ' Clear buffers
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 = 5
i = 0
'****************************************************
TRISA.4 = 1 ' RA4/T0CKI = input to TMR0 counter
TRISA.0 = 0 ' RA0 = output for LED
CMCON = 7 ' All digital
'If you prefer, then increment on low-to-high transitions
T0CON = %11111000
'*****************************************************
USBInit ' Initialize USART
' Main Program Loop
Loop1:
Lcdout $fe, 128, "Counter: ", #i
USBService ' Must service USB regularly
TMR0L = 0 ' Clear TMR0 count before start
'**************ADDED COde
gosub usbtx ' transmit character c to pc
'****************************
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
usbtx:
USBService
Buffer2[0] = 99
Buffer2[1] = 13
USBOut 3, Buffer2, cnt,usbtx
return
The above code I use to attempt sending to pc...BTW I dont know what happened (T0CON = %11111000 and ADCON1 = %00001111) to the bits (but I think I did not alter it).
thanks,
tacbanon
-
Re: Counting led blinks..
Does the Loop2 part still work in the code with the usbtx sub routine? It looks to me like it should work. Or maybe it is too long between USBservices.
If that is the case include the routine to service the USB in the background like the example gave for testing.
-
Re: Counting led blinks..
Hi, yes Loop2 still works(i increments), but I wonder why usbtx does not sends the "c" character to pc?
regards,
tacbanon
-
Re: Counting led blinks..
Give this a shot. It works here.
Code:
INCLUDE "cdc_desc.bas"
INCLUDE "USB_ASM_Service.pbp" ' Base Interrupt System
LED VAR PORTB.0
Buffer VAR BYTE[10]
Buffer2 VAR BYTE[10]
Cnt VAR BYTE
i var byte
ADCON1 = 15 ' Set all I/Os to Digital
CMCON = 7 ' Disable Comparators
Cnt = 5
i = 0
'****************************************************
TRISA.4 = 1 ' RA4/T0CKI = input to TMR0 counter
'If you prefer, then increment on low-to-high transitions
T0CON = 111000
LOW LED
Loop1:
TMR0L = 0 ' Clear TMR0 count before start
'**************ADDED COde
gosub usbtx ' transmit character c to pc
'****************************
Loop2:
WHILE TMR0L = 0 ' Wait for high-to-low transition
WEND ' on RA4/T0CKI
pause 5
PORTA.2 = 1 ' LED on to indicate transition seen LED PORTA.2
i=i+1 ' Clear screen
buffer[0] = 49
Buffer[1] = 13
USBOut 3, Buffer, 2,Loop2
LOW LED ' LED off
goto Loop1
usbtx:
TOGGLE LED
Buffer2[0] = 99
Buffer2[1] = 13
USBOut 3, Buffer2,2,usbtx
return
-
1 Attachment(s)
Re: Counting led blinks..
Hi, thanks for the time. I run your code...but the character "c" appears only when a pulse is detected in my setup. Hmm it should be running as expected...
regards,
tacbanon
-
Re: Counting led blinks..
That is what I thought you wanted?
If you want it to send "C" continuously
Code:
WHILE TMR0L = 0 ' Wait for high-to-low transition
GOSUB usbtx
PAUSE 100
WEND ' on RA4/T0CKI
-
Re: Counting led blinks..
Hi, sorry if was not making clear..it's working now:). acctually the reason I need to send "c" is to identify if the usb device is connected to the my pc application. My next step is to incorporate rtc and sdcards for record keeping. I will post my code later... thanks mackrackit.
regards,
tacbanon
-
Re: Counting led blinks..
-
1 Attachment(s)
Re: Counting led blinks..
Hi, sorry for the delay. I managed to send and display the content of the rtc to communication terminal using CDC.
Next I tried to incorporate the SDcard using macrackit's codes. As I understood the code, once powered it should write a filename(timestamp) to sdcard. But When I checked the sdcard there was none.
This is the code...
Code:
asm ;_PLLDIV_2_1L EQU H'F9' ; Divide by 2 (8 MHz oscillator input)
; __CONFIG _CONFIG1L, _PLLDIV_2_1L & _CPUDIV_OSC1_PLL2_1L & _USBDIV_2_1L
;__CONFIG _CONFIG1L, _PLLDIV_5_1L & _CPUDIV_OSC1_PLL2_1L & _USBDIV_2_1L
;__CONFIG _CONFIG1H, _FOSC_HSPLL_HS_1H & _FCMEN_OFF_1H & _IESO_OFF_1H
__CONFIG _CONFIG1L, _PLLDIV_1_1L & _CPUDIV_OSC1_PLL2_1L & _USBDIV_2_1L
; ; ; USB clock source comes from the 96 MHz PLL divided by 2
; ; [OSC1/OSC2 Src: /1][96 MHz PLL Src: /2]
; No prescale (4 MHz oscillator input drives PLL directly)
;__CONFIG _CONFIG1H, _FOSC_XTPLL_XT_1H & _FCMEN_OFF_1H & _IESO_OFF_1H '2
; ; ; Oscillator Switchover mode disabled
; ; Fail-Safe Clock Monitor disabled
; XT oscillator, PLL enabled, XT used by USB
__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
'RTC pins on 4550
'SDA Var PORTB.0
'SCL Var PORTB.1
' 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 PORTA.5 ' SPI data in SD #7
SDI_TRIS VAR TRISA.5 ' SPI data in direction
SCL VAR PORTA.3 ' SPI clock SD #5
SCL_TRIS VAR TRISA.3 ' SPI clock direction
SD_CS VAR PORTC.2 ' SD card chip select SD #1
SD_CS_TRIS VAR TRISC.2 ' SD card chip select direction
SD_CD VAR PORTC.0 ' SD card detect
SD_CD_TRIS VAR TRISC.0 ' SD card detect direction
SDO VAR PORTC.1 ' SPI data out SD #2
SDO_TRIS VAR TRISC.1 ' SPI data out direction
INCLUDE "SDFS.PBP"
SDC_UseHardSPI = FALSE ' Use hardware SSP port for SPI.
'########################################################################################3
INCLUDE "cdc_desc.bas"
INCLUDE "DT_INTS-18.bas"
INCLUDE "ReEnterPBP-18.bas"
ASM
INT_LIST macro ; IntSource, Label, Type, ResetFlag?
INT_Handler INT_INT, _CNT_PLUS, PBP, yes
INT_Handler USB_INT, _SERVICE_USB, ASM, yes
endm
INT_CREATE ; Creates the interrupt processor
ENDASM
'#########
'START USB AND INTERRUPTS
PAUSE 100 'TIME TO SETTLE
USBINIT 'INITIALIZE USB
USBSERVICE 'SERVICE USB
UIE = $7F 'ENABLE USB INTERRUPTS
UEIE = $9F 'ENABLE USB ERROR INTERRUPTS
PAUSE 500 'MORE TIME
USBINIT
USBSERVICE
@ INT_ENABLE USB_INT
'
'##########################################################################################
ADCON1 = %00001110
LED VAR PORTA.2
TEXT_TIME VAR BYTE[6]
TEXT_DATE VAR BYTE[6]
CRON VAR BYTE[11]
CRON_D VAR BYTE[11]
TEXT_NO_CARD VAR BYTE[9]
MAC_FileName VAR BYTE[11]
T_BUFFER VAR BYTE[8]
T_ONES VAR BYTE
T_TENS VAR BYTE
T_HUNS VAR BYTE
B0 VAR BYTE
B1 VAR BYTE
CNT VAR WORD
CIU VAR BYTE 'CARD IN USE
'RTC DEFINES
DS_SCL VAR PORTB.1 'CLOCK
DS_SDA VAR PORTB.2 'DATA
RTC CON %11010000
SEC_REG CON $00
CONT_REG CON $0E
CNTRL CON %00000000
'##########################################################################################
'RTC VARS
sec VAR BYTE: mins VAR BYTE: hr VAR BYTE: day VAR BYTE
date VAR BYTE: mon VAR BYTE: yr VAR BYTE
'RTC DEC VARS
SEC_O VAR BYTE: SEC_T VAR BYTE:
MIN_O VAR BYTE: MIN_T VAR BYTE
HR_O VAR BYTE: HR_T VAR BYTE:
MON_O VAR BYTE: MON_T VAR BYTE
DATE_O VAR BYTE: DATE_T VAR BYTE:
YR_O VAR BYTE: YR_T VAR BYTE
'SD CARD FILE
FILE_seconds VAR BYTE: FILE_minutes VAR BYTE: FILE_hours VAR BYTE
FILE_day VAR BYTE: FILE_month VAR BYTE: FILE_year VAR BYTE
'#########
'SETS FILE NAME TO THE TIME BOARD IS POWERED
GOSUB READ_RTC
MAC_FileName[0] = $30+HR_T
MAC_FileName[1] = $30+HR_O
MAC_FileName[2] = $30+MIN_T
MAC_FileName[3] = $30+MIN_O
MAC_FileName[4] = $30+SEC_T
MAC_FileName[5] = $30+SEC_O
MAC_FileName[6] = " "
MAC_FileName[7] = " "
MAC_FileName[8] = "T"
MAC_FileName[9] = "X"
MAC_FileName[10] = "T"
'##########################################################################################
FOR B0 = 0 TO 5
LOOKUP B0,[" TIME "],B1
TEXT_TIME(B0) = B1
NEXT B0
FOR B0 = 0 TO 5
LOOKUP B0,[" DATE "],B1
TEXT_DATE(B0) = B1
NEXT B0
FOR B0 = 0 TO 9
LOOKUP B0,[" NO CARD",$d,$a],B1
TEXT_NO_CARD(B0) = B1
NEXT B0
'##########################################################################################
CMCON = %00000111 ' Comparators = off
ADCON1 = %00001111 ' A/D converter off
' Initialize LCD
LCDOUT $FE,1:FLAGS=0:PAUSE 250:LCDOUT $FE,1:PAUSE 250
Goto mainloop ' Skip over subroutines
'ISRs
CNT_PLUS:
IF CIU = 1 THEN
PWM LED,75,250
ELSE
IF (SD_WE = 0) AND (SD_CD = 0) THEN
TOGGLE LED
ELSE
LOW LED
ENDIF
ENDIF
CNT = CNT + 1
@ INT_RETURN
'#########
' Subroutine to read time from RTC
READ_RTC:
I2CREAD DS_SDA, DS_SCL, RTC, SEC_REG, [sec,mins,hr,day,date,mon,yr]
SEC_T = sec & $70
SEC_T = SEC_T>>4
SEC_O = sec & $0F
MIN_T = mins & $70
MIN_T = MIN_T>>4
MIN_O = MINs & $0F
HR_T = hr & $70
HR_T = HR_T>>4
HR_O = hr & $0F
MON_T = mon & $70
MON_T = MON_T>>4
MON_O = mon & $0F
DATE_T = date & $70
DATE_T = DATE_T>>4
DATE_O = date & $0F
YR_T = yr & $70
YR_T = YR_T>>4
YR_O = yr & $0F
CRON[0] = " "
CRON[1] = $30+HR_T
CRON[2] = $30+HR_O
CRON[3] = ":"
CRON[4] = $30+MIN_T
CRON[5] = $30+MIN_O
CRON[6] = ":"
CRON[7] = $30+SEC_T
CRON[8] = $30+SEC_O
CRON[9] = $d
CRON[10] = $a
CRON_D[0] = " "
CRON_D[1] = $30+MON_T
CRON_D[2] = $30+MON_O
CRON_D[3] = "/"
CRON_D[4] = $30+DATE_T
CRON_D[5] = $30+DATE_O
CRON_D[6] = "/"
CRON_D[7] = $30+YR_T
CRON_D[8] = $30+YR_O
CRON_D[9] = $d
CRON_D[10] = $a
FILE_seconds = (SEC_T*10)+SEC_O
FILE_minutes = (MIN_T*10)+MIN_O
FILE_hours = (HR_T*10)+HR_O
FILE_day = (DATE_T*10)+DATE_O
FILE_month = (MON_T*10)+MON_O
FILE_year = (YR_T*10)+YR_O
Return
mainloop:
Gosub READ_RTC ' Read the time from the RTC
' Display time on LCD
Lcdout $fe, 128,"Date:", CRON_D[1],CRON_D[2],CRON_D[3],CRON_D[4],CRON_D[5],CRON_D[6],CRON_D[7],CRON_D[8]
Lcdout $fe, $c0, "Time:", CRON[1], CRON[2],CRON[3],CRON[4],CRON[5],CRON[6],CRON[7],CRON[8]
Pause 500
GOSUB USB_DISPLAY
Goto mainloop
'#########
USB_DISPLAY:
USBOUT 3, TEXT_TIME, 6, mainloop
PAUSE 1
USBOUT 3, CRON, 11, mainloop
PAUSE 1
USBOUT 3, TEXT_DATE, 6, mainloop
PAUSE 1
USBOUT 3, CRON_D, 11, mainloop
PAUSE 1
RETURN
'#########
'####################
@ INT_RETURN
SERVICE_USB:
USBSERVICE
@ INT_RETURN
'#########
'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 STOP
' Display card directory
GOSUB FINDfirst ' Find first file on card
WHILE (FAT_error = 0)
GOSUB FINDnext ' Find next file on card
WEND
SDFILENAME:
' 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] = MAC_FileName[0]
FAT_FileName[1] = MAC_FileName[1]
FAT_FileName[2] = MAC_FileName[2]
FAT_FileName[3] = MAC_FileName[3]
FAT_FileName[4] = MAC_FileName[4]
FAT_FileName[5] = MAC_FileName[5]
FAT_FileName[6] = MAC_FileName[6]
FAT_FileName[7] = MAC_FileName[7]
FAT_FileName[8] = MAC_FileName[8]
FAT_FileName[9] = MAC_FileName[9]
FAT_FileName[10] = MAC_FileName[10]
FAT_seconds = FILE_seconds
FAT_minutes = FILE_minutes
FAT_hours = FILE_hours
FAT_day = FILE_day
FAT_month = FILE_month
FAT_year = FILE_year+20
SDOPEN_W:
' Open a file for write
FAT_mode = "A" ' Write mode APPEND
GOSUB FSfopen ' Open file pointed to by Byte array FAT_FileName
IF (FAT_error = 10) THEN STOP
SD_WRITE_FILE:
' Write to file
FAT_src[0] = "T"
FAT_src[1] = "I"
FAT_src[2] = "M"
FAT_src[3] = "E"
FAT_src[4] = $d
FAT_src[5] = $a
FAT_src[6] = $30+HR_T
FAT_src[7] = $30+HR_O
FAT_src[8] = ":"
FAT_src[9] = $30+MIN_T
FAT_src[10] = $30+MIN_O
FAT_src[11] = ":"
FAT_src[12] = $30+SEC_T
FAT_src[13] = $30+SEC_O
FAT_src[14] = $d
FAT_src[15] = $a
FAT_src[16] = "D"
FAT_src[17] = "A"
FAT_src[18] = "T"
FAT_src[19] = "E"
FAT_src[20] = $d
FAT_src[21] = $a
FAT_src[22] = $30+MON_T
FAT_src[23] = $30+MON_O
FAT_src[24] = ":"
FAT_src[25] = $30+DATE_T
FAT_src[26] = $30+DATE_O
FAT_src[27] = ":"
FAT_src[28] = $30+YR_T
FAT_src[29] = $30+YR_O
FAT_src[30] = $d
FAT_src[31] = $a
FAT_src[32] = " "
FAT_src[33] = $30+T_HUNS
FAT_src[34] = $30+T_TENS
FAT_src[35] = $30+T_ONES
FAT_src[36] = " "
FAT_src[37] = "F"
FAT_src[38] = $d
FAT_src[39] = $a
FAT_src[40] = $d
FAT_src[41] = $a
FAT_count = 42
GOSUB FSfwrite
IF (FAT_error = 10) THEN STOP
IF (FAT_error != 0) THEN STOP
SDCLOSE:
' Close file
GOSUB FSfclose
IF (FAT_error != 0) THEN STOP
PAUSE 5000
CIU = 0
GOTO mainloop
I'm using Pic4550, 4Mhz crystal, PBP2.60. Can you tell me what I'm doing wrong in my setup?
thanks in advance,
tacbanon
-
Re: Counting led blinks..
Okay I missed this line of code in the main loop "GOTO SD_WRITE".
The modified mainloop..
Code:
mainloop:
Gosub READ_RTC ' Read the time from the RTC
' Display time on LCD
Lcdout $fe, 128,"Date:", CRON_D[1],CRON_D[2],CRON_D[3],CRON_D[4],CRON_D[5],CRON_D[6],CRON_D[7],CRON_D[8]
Lcdout $fe, $c0, "Time:", CRON[1], CRON[2],CRON[3],CRON[4],CRON[5],CRON[6],CRON[7],CRON[8]
Pause 500
GOSUB USB_DISPLAY
IF (SD_WE = 0) AND (SD_CD = 0) THEN
GOTO SD_WRITE
ELSE
PWM LED,25,250
USBOUT 3, TEXT_NO_CARD, 10, mainloop
PAUSE 500
ENDIF
Goto mainloop
But this time even the rtc output is not displaying in the communication terminal and freezed on the lcd as well...I'm lost with the sdcard code part.
tacbanon
-
Re: Counting led blinks..
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 STOP
Create a BLINK routine to blink an LED.
Change the above THEN STOP to THEN BLINK.
We need to see if you are getting an error. Better yet, send the error to a display to see what it is.
-
1 Attachment(s)
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
Attachment 6084
regards,
tacbanon
-
Re: Counting led blinks..
Do you have a data sheet for the SD card module?
-
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
-
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
regards,
tacbanon
-
Re: Counting led blinks..
My guess is to try it on pins that are not Schmitt triggered.
-
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
-
Re: Counting led blinks..
oops sorry for the typos(patients) what I meant is patience :)
-
Re: Counting led blinks..
Well, I am not sure why your code is not working on PORTC.3 and PORTC.4. I just tried it here and it is running. The code I used is below.
Port A. Did you turn the analog off? ADC
You have to use an 18Fxx with SDFS as LONG variables are needed.
Code:
' 16F877A RTC
' 10/30/2011
DEFINE OSC 4
#CONFIG
__config _HS_OSC & _WDT_ON & _LVP_OFF & _CP_OFF
#ENDCONFIG
LED VAR PORTB.5
TX VAR PORTD.1 ' DATA SEND PIN
BAUD CON 18030 ' 18030 = 600 BAUD
'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
CMCON = %00000111
' 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
TOGGLE LED
SEROUT2 TX, BAUD,["Date:", hex2 RTCDate, "/",hex2 RTCMonth, "/" , hex2 RTCYear,13]
SEROUT2 TX, BAUD,["Time:", hex2 RTCHour, ":", hex2 RTCMin, ":", hex2 RTCSec,13]
' Lcdout $fe, 128,"Date:", hex2 RTCDate, "/",hex2 RTCMonth, "/" , hex2 RTCYear
' Lcdout $fe, $c0, "Time:", hex2 RTCHour, ":", hex2 RTCMin, ":", hex2 RTCSec
Pause 500
GOTO mainloop
-
Re: Counting led blinks..
okay I think I know whats the problem, I found out that one my file I'm working has this code ADCON1 = %00001111 ' A/D converter off...which is different from the file I post. So this means I have to work on 18F.:)
thanks again,
tacbanon
-
Re: Counting led blinks..
Hi, in the PIC pins and registers for SD/MMC card
Code:
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
PortB.0. PortB.1,PortB.3 and PortB.4 is already in use by a keypad, can I move it to PortD instead?
Like this...
Code:
SD_WE Var PORTA.4 ' SD card write protect
SD_WE_TRIS Var TRISA.4 ' SD card write protect direction
SDI Var PORTD.0 ' SPI data in
SDI_TRIS Var TRISD.0 ' SPI data in direction
SCL Var PORTD.1 ' SPI clock
SCL_TRIS Var TRISD.1 ' SPI clock direction
SD_CS Var PORTD.3 ' SD card chip select
SD_CS_TRIS Var TRISD.3 ' SD card chip select direction
SD_CD Var PORTD.4 ' SD card detect
SD_CD_TRIS Var TRISD.4 ' SD card detect direction
SDO Var PORTC.7 ' SPI data out
SDO_TRIS Var TRISC.7 ' SPI data out direction
Regards,
tacbanon
-
Re: Counting led blinks..
That should not be a problem.
-
Re: Counting led blinks..
Hi, before I change to my desired pins, I made a test(using the original code)...but gives me this "Init: 6 1 255". I don't understand the code I used for testing works before.
Do you know what's causing it?
regards,
tacbanon
-
Re: Counting led blinks..
Open the SDFS file and look at the CE_xxx .
Your card did not initialize. Could be lots of things from a loose wire to a bad card. Bad as in file format corrupt to just wore out.
If the connections are good see if the card can be read in a PC, check the format.
-
Re: Counting led blinks..
Oh my, I think I broke my sdcard module. I double checked the wires I'm using and I reconnect and disconnect them to the devboard more than 10 times still the same result. The SDCard is okay (its in FAT format). I remembered I connect it to PortB earlier the same port where the keypad is also connected. :( this could have ruin the module...
-
Re: Counting led blinks..
For the mean time while I'm waiting for my new sdcard module(will come within a week). I will try to study on eeprom(Pic18F4550's internal). Thank you again to this wonderful forum(people) and to macrackit for the precious time... until nextime.
regards,
tacbanon
-
Re: Counting led blinks..
Hi, I've been playing some time with READ and Write command on the internal eeprom, I'm having trouble updating DATA @6,5,"54321". Probably I'm doing it the hard way. Can you help me out what I'm doing wrong?
Code:
'My Tested Prototype with Pic18F4550 and EEPROMInclude "modedefs.bas"
INCLUDE "C:\PBP\USB18\EE_Vars.pbp" ; Include the EE_var routines
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
ADCON1 = 15 ' Set all I/Os to Digital
CMCON = 7 ' Disable Comparators
INTCON2.7 = 0
'EEprom data
'U1 VAR WORD : @ EE_var _U1, WORD, 9999 ' for later use
DATA @0,5,"12345"
DATA @6,5,"54321"
DATA @13,5,"14332"
DATA @19,5,"24432"
DATA @25,5,"85921"
TRISA = %00000000
TRISD = %00000000
PORTD = %00000000
TRISB = %11110000 ' Set Keypad I/O
PORTB = 0 ' Set columns LOW
PortA = 0
myvarkey var byte
ByteA var Byte[6]
B0 var byte[5]
cnt var byte
x var byte
cnt = 0
asciichar var byte
address var byte
' ---------------------------------[Program Start]----------------------------------------------
serout2 PortD.5,T9600,[$1B,$63,$30]
pause 200
serout2 PortD.5,84,[$1B,$45,"EEPROM"]
serout2 PortD.5,84,[$D,"Studies"]
serout2 PortD.5,84,[$1B,$63,$30]
pause 2000
Serout2 PortD.5,84, [$1B,$45]
main:
@ READKEYPAD _myvarkey
lookup myvarkey,[0,"123A456B789C*0#D"],Key
Serout2 PortD.5,84, [$1B,$45,"Key = ",Key]
if Key = "#" and cnt < 6 then
if ByteA[0]="1" and ByteA[1]="9" then ' wait 19 is pressed before updating
Serout2 PortD.5,84, [$D, "Special Key"]
pause 20
serout2 PortD.5,84,[$D,str ByteA\cnt]
READ 6,x
for address=6 to x+6
Write address+1, ByteA[address]
next address
cnt=0
endif
else
ByteA[cnt]=Key
Serout2 PortD.5,84, [$D, ">" , ByteA[cnt]]
cnt=cnt+1
Endif
if cnt > 5 then
Serout2 PortD.5,84, [$D, "5Digits only"]
cnt = 0
ENdif
if Key = "A" then
READ 0,x
serout2 PortD.5,84,[$D,Dec x," "]
pause 1000
for address=0 to x
READ address,asciichar
serout2 PortD.5,84,[$D,asciichar]
next address
pause 1000
cnt = 0
endif
if Key = "B" then
READ 6,x
serout2 PortD.5,84,[$D,Dec x," "]
pause 1000
for address=0+6 to x+6
READ address,asciichar
serout2 PortD.5,84,[$D,asciichar]
next address
pause 1000
cnt = 0
endif
if Key = "C" then
READ 13,x
serout2 PortD.5,84,[$D,Dec x," "]
pause 1000
for address=0+13 to x+13
READ address,asciichar
serout2 PortD.5,84,[$D,asciichar]
next address
pause 1000
cnt = 0
endif
if Key = "D" then
READ 19,x
serout2 PortD.5,84,[$D,Dec x," "]
pause 1000
for address=0+19 to x +19
READ address,asciichar
serout2 PortD.5,84,[$D,asciichar]
next address
pause 1000
cnt = 0
endif
if Key = "*" then
READ 25,x
serout2 PortD.5,84,[$D,Dec x," "]
pause 1000
for address=0+25 to x +25
READ address,asciichar
serout2 PortD.5,84,[$D,asciichar]
next address
pause 1000
cnt = 0
endif
pause 500
goto main
But updating Data @0 ,"12345" was not a problem, I'm stuck passed @0 location.
regards,
tacbanon
-
Re: Counting led blinks..
This:
Code:
DATA @0,"12345"
DATA @6,"54321"
produces this when the EEPROM is read back
31 |
32 |
33 |
34 |
35 |
00 |
35 |
34 |
33 |
32 |
31 |
00 |
FF |
FF |
Is that what you want?
Did you find out what went bad with the SD card module? You can always use the SD card socket without all the other stuff on the module, it is easy if the MCU is running ~3 volts.
-
Re: Counting led blinks..
Code:
DATA @0,"12345"
DATA @6,"54321"
Sorry If I was not being clear... how can I rewrite them and read back as in the format of "56988" or "65431".
Before overwriting DATA @6,"54321" I can read back as "54321". But after updating it gives me like Hex numbers.
I don't know exactly what happened to sdcard it just dont work as before. But I will try to test it again later.
thanks,
tacbanon
-
Re: Counting led blinks..
Hi mackrackit, sorry if was not making clear. I want to read back from eeprom in the format of example "12345" or "65432" and I can do this uisng the following code.
Code:
if Key = "A" then
READ 0,x
serout2 PortD.5,84,[$D,Dec x," "]
pause 1000
for address=0 to x
READ address,asciichar
serout2 PortD.5,84,[$D,asciichar]
next address
pause 1000
cnt = 0
endif
And I noticed that if I rewrite the value of DATA @6,5,"54321" by entering "19325" and read it back I get "QZu" not "19325"..how do I resolve this?
I will try to test the sdcard tonight, hope something comes up....
thanks,
tacbanon
-
Re: Counting led blinks..
Hi I finally got my eeporm problem solved..I figured that it needs 2 location space in between.
Code:
DATA @0,5,"12345"
DATA @7,5,"54321"
DATA @14,5,"14332"
DATA @21,5,"24432"
DATA @28,5,"85921"
works great...:)
BTW just want to ask if there is a possible to press a key that consist of several characters, for example if I pressed key 1 in successive I can get a character 'a','b','c'. similar to a cellphone keypad.
regards,
tacbanon
-
Re: Counting led blinks..
I found one link http://www.picbasic.co.uk/forum/showthread.php?t=11209 but not sure how to to do it...but I will try..
regards,
tacbanon
-
Re: Counting led blinks..
Melanie's example is good, but the methods talked about at the start of this thread might be better.
Timer/Counter from TIMER0.
It should work well with all of the other stuff going on.