SD Card

2013. 1. 11. 00:10
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

http://www.antcircuits.com/Articles/view/39

 

DataLogger.zip(☜Hex File)

A data logger that store information on SD card.

필요한 부품

PIC18F4550

SD card socket

The PIC program was made using MikroC

 


Coding...

// MMC module connections
sbit Mmc_Chip_Select               at LATA5_bit;  // for writing to output pin always use latch (PIC18 family)
sbit Mmc_Chip_Select_Direction at TRISA5_bit;
// eof MMC module connections
long int temp_res;
const LINE_LEN = 16;                                 ///012345678901234
char file_contents[LINE_LEN] = "XX,XXXXXXXXXXXX";
int temp;
char           filename[] = "TempLogF.TXT";
int i;
unsigned short loop, loop2;


char txt[12];

void M_Create_New_File() {

  Mmc_Fat_Set_File_Date(2010, 4, 19, 9, 0, 0); // Set file date & time info
  Mmc_Fat_Assign(&filename, 0xA0);          // Find existing file or create a new one
  Mmc_Fat_Rewrite();      
 
PORTD=0xFF;                 // To clear file and start with new data
  for(loop = 1; loop <= 9999; loop++) {
   PORTD=0b10100000;
  Delay_1sec();
    Delay_1sec();
    Delay_1sec();

     PORTD=0b01000000;



    file_contents[0] = loop / 10 + 48;
    file_contents[1] = loop % 10 + 48;
   
   
temp_res = ADC_Read(2);
    LongIntToStrWithZeros(temp_res, txt);
    file_contents[3] = (temp_res / 1000) + 48;

    for(i=4;i<=14;i++)
    file_contents[i] = txt[i-4];

    Mmc_Fat_Write(file_contents, LINE_LEN-1);   // write data to the assigned file
    Mmc_Fat_Write("\r\n", 2);   // write data to the assigned file
   // Mmc_Fat_Write('\n', 1); // write data to the assigned file     Delay_1sec();
    Delay_1sec();

  }
}



// Main.

void main() {
  ADCON1 = 12;                  // Configure AN pins as digital
  CMCON  |= 7;                     // Turn off comparators
  TRISD=0x00;
  TRISA=0b00001111;
  
  
PORTD=0b10100000;
   Delay_1sec();
   Delay_1sec();
   PORTD=0b01100000;
   Delay_1sec();
   Delay_1sec();



  // Initialize SPI1 module
  SPI1_Init_Advanced(_SPI_MASTER_OSC_DIV64, _SPI_DATA_SAMPLE_MIDDLE, _SPI_CLK_IDLE_LOW, _SPI_LOW_2_HIGH);
   Delay_ms(10);

   if (Mmc_Fat_Init() == 0)    // reinitialize spi at higher speed
  {
  PORTD=0b11100000;
    SPI1_Init_Advanced(_SPI_MASTER_OSC_DIV4, _SPI_DATA_SAMPLE_MIDDLE, _SPI_CLK_IDLE_LOW, _SPI_LOW_2_HIGH);
    M_Create_New_File();

    PORTD=0b11100000;
  
   
while(1)
    {
         PORTD=0b11100000;
         Delay_1sec();
         Delay_1sec();
         PORTD=0x0;
         Delay_1sec();
         Delay_1sec();
     }
  }
  else {
        PORTD=0b01000000;


  }

}

'MCU Examples (PIC 기반)' 카테고리의 다른 글

Controlling Stepper Motor in FDD(=플로피디스크 드라이브)  (0) 2013.02.24
Parallel Dot Matrix  (0) 2013.02.01
USB  (0) 2013.01.11
Using Relays with Microcontrollers  (0) 2013.01.03
Posted by ElectricShock
:
BLOG main image
잡동사니들(지극히 개인취향인...) (다른글에도 댓글 부탁해요♥) You May Leave English Messages on GuestBook. by ElectricShock

공지사항

카테고리

분류 전체보기 (782)
Programming(=프로그래밍) (3)
MiDi (2)
Animation (4)
Blender (3D Graphic Program.. (10)
Blendtuts.com (Series) (1)
Blender 기초 팁들 (2)
Processing (디지털미디어과) (2)
Music (1)
Books in the world (0)
Communication(CAN, UART, et.. (12)
MCU Examples (PIC 기반) (7)
Transistor (1)
Mikro C Pro (11)
Mikro Pascal (1)
Proton IDE (0)
Robot (0)
Swift 3D (1)
Dummies Series (1)
All about Hacking (0)
제2 외국어 (1)
PIC 해외서적들 (3)
AVR (25)
PIC (MikroC) (MPLAB) (4)
Assembly (2)
ARM (3)
Arduino (26)
PSpice (1)
Proteus ISIS (14)
CodeVision (2)
FPGA (15)
MPLAB (24)
PCB (the Procedure) (15)
3D Printer (5)
PICKIT3 (6)
Matlab (11)
RaspBerry PI (15)
BeagleBone (1)
Android Studio (17)
졸업작품 (172)
Korea History (0)
Issue(사회) (73)
Multimeter 리뷰 (1)
Oscilloscope (1)
A (34)
B (19)
J (6)
C (32)
P (12)
T (37)
H (12)
I (12)
M (44)
R (5)
E (5)
F (2)
D (9)
O (2)
L (7)
S (9)
W (2)
V (6)
G (14)
Visual C++ or Visual Studio (2)
Android App Development (0)

최근에 올라온 글

최근에 달린 댓글

최근에 받은 트랙백