سلام یه نمونه پروژه mmc تو بسکام می خواستم
کسی کتابخونه MMCSD_HC.LIB که خود بسکام برای xmega گزاشته رو داره
کسی کتابخونه MMCSD_HC.LIB که خود بسکام برای xmega گزاشته رو داره
$regfile = "xm128a1def.dat" $crystal = 32000000 '32MHz $hwstack = 128 $swstack = 128 $framesize = 128 $lib "xmega.lib" $external _xmegafix_clear $external _xmegafix_rol_r1014 Config Osc = Enabled , 32mhzosc = Enabled 'We use internal 32MHz Config Sysclock = 32mhz , Prescalea = 1 , Prescalebc = 1_1 'Internal 32MHz, no prescaler Config Priority = Static , Vector = Application , Lo = Enabled 'config interrupts Enable Interrupts $include "CONFIG_AVR-DOS.BAS" $include "Config_MMC.BAS" 'Config Adcb = Single , Convmode = Unsigned , Resolution = 12bit , Dma = Off , Reference = Int1v , Event_mode = None , Prescaler = 32 , Ch0_gain = 1 , Ch0_inp = Single_ended , Mux0 = &B000_00 _ 'Ch1_gain = 1 , Ch1_inp = Single_ended , Mux1 = &B1_000 , Ch2_gain = 1 , Ch2_inp = Single_ended , Mux2 = &B10_000 , Ch3_gain = 1 , Ch3_inp = Single_ended , Mux3 = &B11_000 'Config Adca = Single , Convmode = Unsigned , Resolution = 12bit , Dma = Off , Reference = Arefa , Event_mode = None , Prescaler = 32 , Ch0_gain = 1 , Ch0_inp = Single_ended , Mux0 = &B000_00 _ 'Ch1_gain = 1 , Ch1_inp = Single_ended , Mux1 = &B1_000 , Ch2_gain = 1 , Ch2_inp = Single_ended , Mux2 = &B10_000 , Ch3_gain = 1 , Ch3_inp = Single_ended , Mux3 = &B11_000 '''ADC mux value:0=ADC0,8=ADC1,16=ADC2,24=ADC3,32=ADC4,40=ADC5,48=ADC6,56=ADC7 Config Submode = New Config Portf = Output Config Porte = Output Config Portd = Output Config Portk = Output Color_lcd_cs Alias Portf.2 Color_lcd_rs Alias Portf.3 Color_lcd_wr Alias Portf.1 Color_lcd_rd Alias Portf.4 Color_lcd_rst Alias Portf.0 Color_lcd_lsb_port Alias Porte Color_lcd_msb_port Alias Portd **************************************************************************************************** اینم از کد مربوط به فایل config-mmc ****************************************************************************************************** ' THIS IS AN INCLUDE FILE ' DO NOT COMPILE $nocompile '------------------------------------------------------------------------------- ' Config_MMC.BAS ' Config File for MMC Flash Cards Driver ' (c) 2003-2005 , MCS Electronics / Vِgel Franz Josef '------------------------------------------------------------------------------- ' Place MMC.LIB in the LIB-Path of BASCOM-AVR installation ' 'Connection as following 'MMC M128/M103 '1 MMC_CS PORTB.0 '2 MOSI PORTB.2 '3 GND '4 +3.3V '5 CLOCK PORTB.1 '6 GND '7 MISO, PORTB.3 ' you can vary MMC_CS on HW-SPI and all pins on SOFT-SPI, check settings ' ========== Start of user definable range ===================================== ' you can use HW-SPI of the AVR (recommended) or a driver build in Soft-SPI, if ' the HW-SPI of the AVR is occupied by an other SPI-Device with different settings ' Declare here you SPI-Mode ' using HW-SPI: cMMC_Soft = 0 ' not using HW_SPI: cMMC_Soft = 1 Const Cmmc_soft = 0 #if Cmmc_soft = 0 ' --------- Start of Section for HW-SPI ---------------------------------------- Portc_pin6ctrl = &B00_011_000 ' define Chip-Select Pin Config Pinc.4 = Output ' define here Pin for CS of MMC/SD Card Mmc_cs Alias Portc.4 Set Mmc_cs ' Define here SS Pin of HW-SPI of the CPU (f.e. Pinb.0 on M128) Config Pinc.4 = Output ' define here Pin of SPI SS Spi_ss Alias Portc.4 Set Spi_ss ' Set SPI-SS to Output and High por Proper work of Set Portc.4 ' SPI as Master ' HW-SPI is configured to highest Speed Config Spic = Hard , Data_order = Msb , Master = Yes , Mode = 0 , Clockdiv = Clk2 Open "SPIC" For Binary As #14 Spiinit ' Init SPI ' --------- End of Section for HW-SPI ------------------------------------------ #else ' Config here SPI pins, if not using HW SPI ' --------- Start of Section for Soft-SPI -------------------------------------- ' Chip Select Pin => Pin 1 of MMC/SD Config Pinc.3 = Output Mmc_cs Alias Portc.3 Set Mmc_cs ' MOSI - Pin => Pin 2 of MMC/SD Config Pinc.5 = Output Set Portc.5 Mmc_portmosi Alias Portc.5 Bmmc_mosi Alias 5 ' MISO - Pin => Pin 7 of MMC/SD Config Pinc.6 = Input Mmc_portmiso Alias Pinc.6 Bmmc_miso Alias 6 ' SCK - Pin => Pin 5 of MMC/SD Config Pinc.7 = Output Set Portc.7 Mmc_portsck Alias Portc.7 Bmmc_sck Alias 7 ' --------- End of Section for Soft-SPI ---------------------------------------- #endif ' ========== End of user definable range ======================================= ' Error Const Cperrdrivereset = 225 ' Error response Byte at Reset command Const Cperrdriveinit = 226 ' Error response Byte at Init Command Const Cperrdrivereadcommand = 227 ' Error response Byte at Read Command Const Cperrdrivewritecommand = 228 ' Error response Byte at Write Command Const Cperrdrivereadresponse = 229 ' No Data response Byte from MMC at Read Const Cperrdrivewriteresponse = 230 ' No Data response Byte from MMC at Write Const Cperrdrive = 231 Const Cperrdrivenotsupported = 232 ' return code for DriveGetIdentity, not supported yet Waitms 100 ' Wait some time before initialising MMC/SD Dim Gbdriveerror As Byte ' General Driver Error register Dim Gbdriveerrorreg As Byte ' Driver load Error-Register of HD in case of error Dim Gbdrivestatusreg As Byte ' Driver load Status-Register of HD on case of error Dim Gbdrivedebug As Byte $lib "MMC-XMEGA.LIB" $lib "MMC.LIB" ' link driver library $external _mmc Gbdriveerror = Driveinit() ' Init MMC/SD Card
$regfile = "xm128a1def.dat" $crystal = 32000000 $hwstack = 128 $swstack = 128 $framesize = 128 $lib "xmega.lib" $external _xmegafix_clear $external _xmegafix_rol_r1014 Config Osc = Enabled , 32mhzosc = Enabled ' enable 2 MHz and 32 MHz interal oscillators Config Sysclock = 32mhz , Prescalea = 1 , Prescalebc = 1_1 ' use 32 MHz چون میخواستم از SPIC استفاده کنم 0 گذاشتم: Const Spi_port = 0 ' 0 SPIC ' 1 SPID ' 2 SPIE ' 3 SPIF #if Spi_port = 0 Spi_ctrl Alias Spic_ctrl Spi_status Alias Spic_status Spi_data Alias Spic_data Port_outset Alias Portc_outset Port_dirset Alias Portc_dirset Port_pin6ctrl Alias Portc_pin6ctrl #endif #if Spi_port = 1 Spi_ctrl Alias Spid_ctrl Spi_status Alias Spid_status Spi_data Alias Spid_data Port_outset Alias Portd_outset Port_dirset Alias Portd_dirset Port_pin6ctrl Alias Portd_pin6ctrl #endif #if Spi_port = 2 Spi_ctrl Alias Spie_ctrl Spi_status Alias Spie_status Spi_data Alias Spie_data Port_outset Alias Porte_outset Port_dirset Alias Porte_dirset Port_pin6ctrl Alias Porte_pin6ctrl #endif #if Spi_port = 3 Spi_ctrl Alias Spid_ctrl Spi_status Alias Spif_status Spi_data Alias Spif_data Port_outset Alias Portf_outset Port_dirset Alias Portf_dirset Port_pin6ctrl Alias Portf_pin6ctrl #endif '!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ' ! ' Important : SDC chip select is defined in Config_MMCSD_HC.bas ! ' ! '!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Dim Temp As Byte Osc_pllctrl = &H10 Osc_ctrl = &H11 Do Temp = Osc_status And &H10 Loop Until Temp = &H10 Cpu_ccp = &HD8 Clk_ctrl = &H04 Portf_dirset = &H2 Dim B As Byte Dim L As Long Dim Ff As Byte Dim S As String * 30 Dim Diskf As Long Dim Disks As Long '------------------------------------------------------------------------------- $include "Config_AVR-DOS.BAS" $include "Config_MMCSD_HC.bas" 'include mmc Ff = Drivereset() Ff = Driveinit() $external Waitms If Gbdriveerror <> 0 Then Cls Lcd "Error Config" End End If 'switch to fast SPI Spi_ctrl = &HD0 'include avr-dos B = Initfilesystem(1) If B <> 0 Then Lcd "Error MMC" Locate 2 , 1 Lcd "Open file" Ff = Freefile() Open "test.txt" For Output As #ff S = "This is for test" For L = 0 To 10000 Print #ff , S Next L Close #ff Locate 3 , 1 Lcd "File Closed" Do Loop
#if Cmmc_soft = 0 ' --------- Start of Section for HW-SPI ---------------------------------------- ' define Chip-Select Pin Config Pinc.4 = Output ' define here Pin for CS of MMC/SD Card Mmc_cs Alias Portc.4 Set Mmc_cs ' Define here SS Pin of HW-SPI of the CPU (f.e. Pinb.0 on M128) ''Config Pinb.4 = Output ' define here Pin of SPI SS ''Spi_ss Alias Portb.4 ''Set Spi_ss ' Set SPI-SS to Output and High por Proper work of ' SPI as Master ' HW-SPI is configured to highest Speed ''Config Spi = Hard , Interrupt = Off , Data Order = Msb , Master = Yes , Polarity = High , Phase = 1 , Clockrate = 4 , Noss = 1 ' Spsr = 1 ' Double speed on ATMega128 ''Spiinit Port_outset = &H80 Port_dirset = &HB0 Port_pin6ctrl = &H18 If _xtal < 1000000 Then Spi_ctrl = &H50 Elseif _xtal >= 1000000 And _xtal <= 4000000 Then Spi_ctrl = &H51 Elseif _xtal > 4000000 And _xtal <= 16000000 Then Spi_ctrl = &H52 Else Spi_ctrl = &H53 End If ' Spi_ctrl = &H51 ' for 2 MHz clock ' Spi_ctrl = &H53 ' for 32MHz clock ' --------- End of Section for HW-SPI ------------------------------------------ #else ' Config here SPI pins, if not using HW SPI ' --------- Start of Section for Soft-SPI -------------------------------------- ' Chip Select Pin => Pin 1 of MMC/SD Config Pinc.4 = Output Mmc_cs Alias Portc.4 Set Mmc_cs ' MOSI - Pin => Pin 2 of MMC/SD Config Pinc.5 = Output Set Pinc.5 Mmc_portmosi Alias Portc Bmmc_mosi Alias 2 ' MISO - Pin => Pin 7 of MMC/SD Config Pinc.6 = Input Mmc_portmiso Alias Pinc Bmmc_miso Alias 3 ' SCK - Pin => Pin 1 of MMC/SD Config Pinc.7 = Output Set Pinc.7 Mmc_portsck Alias Portc Bmmc_sck Alias 1 ' --------- End of Section for Soft-SPI ---------------------------------------- #endif
دیدگاه