Information Technology Reference
In-Depth Information
The IsWriteProtected function returns true if the card has a write-protect
tab that is set to write protect.
byte IsWriteProtected(void)
{
if (MEDIA_WD) return TRUE;
else return FALSE;
}
Delay Timer
A function that returns after a specific delay time is often useful for tasks
such as waiting for hardware to initialize. The Delayms function uses an
on-chip hardware timer to delay the number of milliseconds passed to the
function. When the time has elapsed, the function returns. This function is
very specific to the PICMicro architecture and accesses registers defined in
the compiler file p18f4550.h. Firmware for other chips can perform equiva-
lent functions using hardware timers in the chips.
#define SYSTEM_CLOCK (dword) 20000000 // Set to Fosc frequency.
#define CLKSPERINSTRUCTION (byte) 4
#define TMR1PRESCALER (byte) 8
#define TMR1OVERHEAD (byte) 5
#define MILLISECDELAY (word)((SYSTEM_CLOCK / CLKSPERINSTRUCTION /
TMR1PRESCALER / (word)1000) - TMR1OVERHEAD)
void Delayms(byte milliseconds)
{
T1CON = 0xB0; // Initialize the timer 1 control register.
TMR1IE = 1; // Enable the timer 1 overflow interrupt.
do {
TMR1H = high(0xFFFF - MILLISECDELAY); // Load the timer registers.
TMR1L = low(0xFFFF - MILLISECDELAY);
TMR1IF = 0;
// Clear the overflow flag.
TMR1ON = 1;
// Start the timer.
while (!TMR1IF){;}
// Wait for timer overflow.
TMR1ON = 0;
// Stop the timer.
Nop();
// Additional delay for accuracy.
Nop();
// Additional delay for accuracy.
milliseconds--;
// Decrement the number of milliseconds to delay.
// Quit after the specified number of milliseconds has elapsed.
} while (milliseconds > 0);
Search WWH ::




Custom Search