Пример #1
0
void ToggleEpinOfLCD(void)
{
	LCD_E = 1;                // Give a pulse on E pin
	__delay_us(E_Delay);      // so that LCD can latch the
	LCD_E = 0;                // data from data bus
	__delay_us(E_Delay); 	
}
Пример #2
0
/*==============================================================================
 Send Function (Called by sendfivetimes function)
==============================================================================*/
void send(unsigned char cAddress, unsigned char cCommand, unsigned char c, unsigned char flip) {
    if (c == 1) {
        pingSony(91);
        __delay_us(700);
        i = 0;
        j = 0;
        while (i < 7) {
            cTemp = cCommand & 0b00000001; //AND THE VALUE WITH BINARY NUMBER TO CHECK IF THE LSB IS 0
            if (cTemp == 1) {
                pingSony(44);
            } else {
                pingSony(21);

            }
            cCommand = cCommand >> 1; //BIT SHIFT OVER 1
            __delay_us(680);
            i++;
        }
        while (j < 5) {
            cTemp = cAddress & 0b00000001; //AND THE VALUE WITH BINARY NUMBER TO CHECK IF THE LSB IS 0
            if (cTemp == 1) {
                pingSony(44);

            } else {
                pingSony(21);
            }
            cAddress = cAddress >> 1; //BIT SHIFT OVER 1
            __delay_us(680);
            j++;
        }
    } else if (c == 2) {
Пример #3
0
int main(int argc, char** argv) {
    pic_setup();
    volatile int i=0;
    int div=100  ;
    int gate1=300;

    int gate2=1000;
    int t1 = gate1;
    int t2 = gate2-t1;

 while (1) {
     sound(300,30);
     sound(150,45);
  }



     while (1) {
        DEBUG_LED = 1;
        for (i=0; i<t1; i+=1) { __delay_us(1); }

        DEBUG_LED = 0;
        for (i=0; i<t2; i+=1) { __delay_us(1); }

        t1+=div;
        t2-=div;

        if (t1>gate2 || t1<gate1) {
            div=-div;;
        }

    }

    return (EXIT_SUCCESS);
}
Пример #4
0
void delay_us(unsigned int value)										//Workaround f�r gr�ssere Delays bei 20MHz Systemtakt
{
	for(;value>=100;value-=100)
		__delay_us(100);
	for(;value>=10;value-=10)
		__delay_us(10);	
}
Пример #5
0
unsigned char ow_reset()
{
    unsigned char ret = 0;

    di();

    // Pulling pin low
    //PORTBbits.RB4 = 0;
    //TRISBbits.TRISB4 = 0;
    ONEWIRE_PORT = 0;
    ONEWIRE_TRIS = 0;

    __delay_us(490);
    // Pulling up
    //TRISBbits.TRISB4 = 1;
    ONEWIRE_TRIS = 1;
    // Checking for response
    __delay_us(60);
    //if( PORTBbits.RB4 == 0 ){
    if( ONEWIRE_PORT == 0 ){
        //printf("DS18b20 responded\r\n");
        ret = 1;
    }else{
        //printf("ONEWIRE ERROR: Device didnt respond\r\n");
        ret = 0;
    }
    
    ei();
    __delay_us(450);

    return ret;
}
Пример #6
0
/*
 * LcdWaitBF
 * Description: This procedure simply loops until the LCD is not busy.
 *              This clears the RS bit.
 *
 * Argument:    None
 * Return:      None
 *
 * Input:       LCD's Busy Flag
 * Output:      None
 *
 * Operation:   Keep on looping and reading the LCD busy flag. Exit when it 
 *              indicates the LCD is not busy.
 *
 * Revision History:
 *   Dec. 16, 2012      Nnoduka Eruchalu     Initial Revision
 */
void LcdWaitBF(void)
{
  unsigned char busy, status=0x00;
  LCD_DATA_TRIS = 0xFF;        /* when reading a port change it to an input */
  
  CLEAR_RS();                  /* prepare to read BF and Address Counter */
  SET_RW();                    /* and put the LCD in read mode */
  
  do {
    SET_E();                   /* during reads the E has to be active */
    __delay_us(0.5);           /* wait tPW for data to become available */
    
    status = LCD_DATA_PORT;    /* read in value on data lines */
    busy = status & 0x80;      /* busy flag is highest status bit */
    
    __delay_us(0.5);
    
    CLEAR_E();                 /* pull E low for at least tC-tPW */ 
    __delay_us(1);            
  } while(busy);
  
  /* put the LCD in write mode */
  CLEAR_RW();                  /* in write mode when R/W\ is cleared */
  LCD_DATA_TRIS = 0x00;        /* and the I/O pins are set as outputs */
}
Пример #7
0
/*
 * LcdInit
 * Description: This initializes the LCD. This must be called before the LCD can
 *              be used.
 *              Thus this function has to be called before calling any other 
 *              LCD-interface functions.
 *              The LCD is set to the following specifications:
 *                8-bit mode, 4-line display, 5x8 font
 *                cursor INCs, display doesn't shift
 *                cursor visible, cursor blinking
 *
 * Argument:    None
 * Return:      None
 *
 * Input:       None
 * Output:      LCD
 *
 * Operation:   
 *   Really just follows standard initialization sequence. See sketch below
 *
 *   POWER ON
 *       |
 *       |  Wait time >40ms
 *      \|/
 *   FUNCTION SET (RS = 0, RW=0, DB = 0b0011NFXX) [BF cannot be checked b4 this]
 *       |
 *       |  Wait time >37us
 *      \|/
 *   FUNCTION SET (RS = 0, RW=0, DB = 0b0011NFXX) [BF cannot be checked b4 this]
 *       |
 *       |  Wait time >37us
 *      \|/
 *   DISPLAY ON/OFF control (RS = 0, RW=0, DB = 0b00001DCB)
 *       |
 *       |  Wait time >37us
 *      \|/
 *   DISPLAY Clear (RS=0, RW=0, DB=0b00000001)
 *       |
 *       |  Wait time >1.52ms
 *      \|/
 *   Entry Mode Set (RS=0, RW=0, DB=0b0000001{I/D}S)
 *       |
 *       |  Wait time >37us
 *      \|/
 *   Initialization End
 *
 * Revision History:
 *   Dec. 16, 2012      Nnoduka Eruchalu     Initial Revision
 */
void LcdInit(void)
{
  LCD_DATA_TRIS = 0x00;        /* setup LCD IO ports as outputs */
  LCD_E_TRIS = 0;
  LCD_RW_TRIS = 0;
  LCD_RS_TRIS = 0;
  
  LCD_DATA_LAT = 0;            /* clear IO lines*/
  CLEAR_RS(); CLEAR_RW(); CLEAR_E();
  
  __delay_ms(40);              
  
  LCD_DATA_LAT = LCD_FUNC_SET; /* FUNCTION SET, done manually to prevent a */
  LCD_STROBE();                /* BF check before next command */
  __delay_us(40);
  
  LcdCommand(LCD_FUNC_SET);    /* FUNCTION SET, again done manually */
  LCD_STROBE();
  __delay_us(40);
  
  LcdCommand(LCD_ON);          /* DISPLAY ON/OFF control: Turn display on */
  __delay_us(40);
  
  LcdCommand(LCD_CLEAR);        /* DISPLAY Clear */
  __delay_ms(2);
  
  LcdCommand(LCD_ENTRY_MD);     /* ENTRY mode set */
  
  GenSpecChars();               /* Now create some special characters */
}
Пример #8
0
/************************************************************************
* Function: void DRV_TCON_SPI_CommandWrite(uint8_t index, uint16_t value)
*                                                                       
* Overview: This writes a word to SPI module.
*                                                                       
* Input: index - The index (or address) of the register to be written.
*        value - The value that will be written to the register.
*                                                                       
* Output: none                                 
*                                                                       
************************************************************************/
void DRV_TCON_SPI_CommandWrite(uint16_t index, uint16_t value)
{
    typedef union
    {
        uint8_t  indexByte[2];
        uint16_t indexValue;
    }  GFX_TCON_INDEX;

    TCON_CS_LAT = 0;

    // Command
    TCON_DC_LAT = 0;
    DRV_SPI_Put(spiInitData.channel, ((GFX_TCON_INDEX)index).indexByte[1]);
    DRV_SPI_Put(spiInitData.channel, ((GFX_TCON_INDEX)index).indexByte[0]);

    TCON_CS_LAT = 1;
    __delay_us(10);
    TCON_CS_LAT = 0;

    // Data
    TCON_DC_LAT = 1;
    DRV_SPI_Put(spiInitData.channel, ((GFX_TCON_INDEX)value).indexByte[1]);
    DRV_SPI_Put(spiInitData.channel, ((GFX_TCON_INDEX)value).indexByte[0]);

    TCON_CS_LAT = 1;
    __delay_us(10);
}
Пример #9
0
//common shift register clock to move serial data aalong.
void SRCLK(void)
{
    PORTCbits.RC4=1;
    __delay_us(100);
    PORTCbits.RC4=0;
    __delay_us(100);
}
int KEYPAD_Read(void) {
    
    /* Start the scanning process */
    /* Set only COL1 to 1 and read each row one by one until finding the pressed key */
    PORT_KEYPAD_COL1=1; PORT_KEYPAD_COL2=0; 
    PORT_KEYPAD_COL3=0; PORT_KEYPAD_COL4=0;
    if(PORT_KEYPAD_ROW1) return 1; if(PORT_KEYPAD_ROW2) return 4; 
    if(PORT_KEYPAD_ROW3) return 7; if(PORT_KEYPAD_ROW4) return 14;
    __delay_us(10);
    /* Set only COL2 to 1 and read each row one by one until finding the pressed key */
    PORT_KEYPAD_COL1=0; PORT_KEYPAD_COL2=1; 
    PORT_KEYPAD_COL3=0; PORT_KEYPAD_COL4=0;
    if(PORT_KEYPAD_ROW1) return 2; if(PORT_KEYPAD_ROW2) return 5;
    if(PORT_KEYPAD_ROW3) return 8; if(PORT_KEYPAD_ROW4) return 0;
    __delay_us(10);
    /* Set only COL3 to 1 and read each row one by one until finding the pressed key */
    PORT_KEYPAD_COL1=0; PORT_KEYPAD_COL2=0;
    PORT_KEYPAD_COL3=1; PORT_KEYPAD_COL4=0;
    if(PORT_KEYPAD_ROW1) return 3; if(PORT_KEYPAD_ROW2) return 6;
    if(PORT_KEYPAD_ROW3) return 9; if(PORT_KEYPAD_ROW4) return 15;
    __delay_us(10);
    /* Set only COL4 to 1 and read each row one by one until finding the pressed key */
    PORT_KEYPAD_COL1=0; PORT_KEYPAD_COL2=0;
    PORT_KEYPAD_COL3=0; PORT_KEYPAD_COL4=1;
    if(PORT_KEYPAD_ROW1) return 10; if(PORT_KEYPAD_ROW2) return 11;
    if(PORT_KEYPAD_ROW3) return 12; if(PORT_KEYPAD_ROW4) return 13;
    __delay_us(10);

    return 0xFF; /* Not pressed condition */
}
Пример #11
0
//clock to place data from internal latches onto outputs
void OutCLK(void)
{
    PORTAbits.RA5=1;
    __delay_us(100);
    PORTAbits.RA5=0;
    __delay_us(100);
}
Пример #12
0
unsigned char ow_read_byte()
{
    unsigned char i;
    unsigned char data = 0;
    
    di();
    for(i=0;i<8;i++){
        data >>= 1;
        //TRISBbits.TRISB4 = 0;
        ONEWIRE_TRIS = 0;
        __delay_us(1);
        //TRISBbits.TRISB4 = 1;
        ONEWIRE_TRIS = 1;
        __delay_us(5);

       //if(PORTBbits.RB4 == 1)
       if(ONEWIRE_PORT == 1)
        data = data | 0x80;

        __delay_us(55);
     }
    ei();

    return data;
}
Пример #13
0
/*******************************************************************************
*  LCD_Clear( )                                                                *
*    ???????????????????????                            *
*    ???Display Data RAM(2x40byte)?20H?????????????           *
*    ?????????????                                                *
*******************************************************************************/
void LCD_Clear(void)
{
     command(0x01) ;     // Clear Display : ?????20H???????????????col=0,row=0???
     __delay_us(1100) ;  // LCD???(1.08ms)????????
     command(0x02) ;     // Return Home   : ?????????????
     __delay_us(1100) ;  // LCD???(1.08ms)????????
     LCD_NowPage  = 0 ;  // ???????????????
}
Пример #14
0
void pulse() {
    E = 0;
    __delay_us(5);
    E = 1;
    __delay_us(5);
    E = 0;
    delay_10us(10);
}
Пример #15
0
void i2c_write_bit(int b)
{
     PORTCbits.RC2 = b; // data high
     __delay_us(i2c_period/2);
     PORTCbits.RC1 = 1; // clock high
     __delay_us(i2c_period/2);
     PORTCbits.RC1 = 0; // clock low
}
Пример #16
0
void sound(int d, int p){
    for (volatile int i=1; i<d; i++){
        DEBUG_LED = 1;
        for (volatile int z=0; z<p; z++) {__delay_us(1); }
        DEBUG_LED = 0;
        for (volatile int z=0; z<p; z++) {__delay_us(1); }
    }
}
//function to output enable clock pulse to LCD
void lcd_e_clock(void)
{
	__delay_us(10);
	LCD_E = 0;	//create a falling edge for Enable pin of LCD to process data
	__delay_us(100);
	LCD_E = 1;	//pull the Enable pin high again
	__delay_us(100);	
}	
Пример #18
0
//clock to place data from inputs to internal latches
void InCLK(void)
{
    PORTBbits.RB7=0;
    __delay_us(100);
    SRCLK();
    PORTBbits.RB7=1;
    __delay_us(100);
}
void LCDInit(uint8_t style)
{
	/*****************************************************************

	This function Initializes the lcd module
	must be called before calling lcd related functions

	Arguments:
	style = LS_BLINK,LS_ULINE(can be "OR"ed for combination)
	LS_BLINK : The cursor is blinking type
	LS_ULINE : Cursor is "underline" type else "block" type
        LS_NONE : No visible cursor

	*****************************************************************/

	//After power on Wait for LCD to Initialize
	__delay_ms(30);

	//Set IO Ports
	LCD_DATA_TRIS&=(~(0x0F<<LCD_DATA_POS)); //Output

        LCD_E_TRIS=0;   //Output
        LCD_RS_TRIS=0;  //Output
        LCD_RW_TRIS=0;  //Output

	LCD_DATA_PORT&=(~(0x0F<<LCD_DATA_POS));//Clear data port

        CLEAR_E();
	CLEAR_RW();
	CLEAR_RS();

	//Set 4-bit mode
	__delay_us(0.5);	//tAS

	SET_E();
	LCD_DATA_PORT|=((0b00000010)<<LCD_DATA_POS); //[B] To transfer 0b00100000 i was using LCD_DATA_PORT|=0b00100000
	__delay_us(1);
	CLEAR_E();
	__delay_us(1);

	//Wait for LCD to execute the Functionset Command
	LCDBusyLoop();                                    //[B] Forgot this delay

	//Now the LCD is in 4-bit mode

	
	LCDCmd(0b00101000);             //function set 4-bit,2 line 5x7 dot format
        LCDCmd(0b00001100|style);	//Display On

	/* Custom Char */
        LCDCmd(0b01000000);

	uint8_t __i;
	for(__i=0;__i<sizeof(__cgram);__i++)
		LCDData(__cgram[__i]);


}
Пример #20
0
int i2c_read_bit()
{
     PORTCbits.RC1 = 1; // clock high
     __delay_us(i2c_period/2);
     int b = PORTCbits.RC2;
     __delay_us(i2c_period/2);
     PORTCbits.RC1 = 0; // clock low
     return b;
}
Пример #21
0
/**
 * I2C stop condition
 */
void I2C_Stop() {
    I2C_SDA_OUT_SET();
    //I2C_SCL_OUT_SET();

    I2C_SCL_SET();
    __delay_us(20);
    I2C_SDA_SET();
    __delay_us(20);
}
Пример #22
0
void writeCommandToLCD(unsigned char Command)  
{
	LCD_RS = 0;				  // It is a command
	LCD_PORT = Command;		  // Write value on data bus
	
	LCD_E = 1;                // Give a pulse on E pin
	__delay_us(E_Delay);      // so that LCD can latch the
	LCD_E = 0;                // data from data bus
	__delay_us(E_Delay); 	
}
Пример #23
0
void i2c_stop()
{
   // clock should already be high
    TRISCbits.TRISC2 = 0;  // data out
    PORTCbits.RC2 = 0;  // ensure data low
    PORTCbits.RC1 = 1;  // clock high
    __delay_us(i2c_period/2);
    PORTCbits.RC2 = 1;  // transition data high
    __delay_us(i2c_period/2);
}
Пример #24
0
void writeDataToLCD(char LCDChar)  
{
	LCD_RS = 1;				  // It is data
	LCD_PORT = LCDChar;		  // Write value on data bus
	
	LCD_E = 1;                // Give a pulse on E pin
	__delay_us(E_Delay);      // so that LCD can latch the
	LCD_E = 0;                // data from data bus
	__delay_us(E_Delay); 
}
Пример #25
0
void LCDByte(uint8_t c,uint8_t isdata)
{
//Sends a byte to the LCD in 4bit mode
//cmd=0 for data
//cmd=1 for command


//NOTE: THIS FUNCTION RETURS ONLY WHEN LCD HAS PROCESSED THE COMMAND

uint8_t hn,ln;			//Nibbles
uint8_t temp;

hn=c>>4;
ln=(c & 0x0F);

if(isdata==0)
	CLEAR_RS();
else
	SET_RS();

__delay_us(0.5);		//tAS

SET_E();

//Send high nibble

temp=(LCD_DATA_PORT & (~(0X0F<<LCD_DATA_POS)))|((hn<<LCD_DATA_POS));
LCD_DATA_PORT=temp;

__delay_us(1);			//tEH

//Now data lines are stable pull E low for transmission

CLEAR_E();

__delay_us(1);

//Send the lower nibble
SET_E();

temp=(LCD_DATA_PORT & (~(0X0F<<LCD_DATA_POS)))|((ln<<LCD_DATA_POS));

LCD_DATA_PORT=temp;

__delay_us(1);			//tEH

//SEND

CLEAR_E();

__delay_us(1);			//tEL

LCDBusyLoop();
}
Пример #26
0
int ADC_Read()
{
// Activamos, convertimos y desactivamos el ADC, hay que dar tiempo para que se habilite 30us
    ADCON0bits.ADON = 1;
    __delay_us(30);
    ADCON0bits.GO = 1;
    while(ADCON0bits.GO == 1) 
    __delay_us(10);
    ADCON0bits.ADON = 0;
    return ADRESHbits.ADRESH;
}
Пример #27
0
void SetToNext(State_t* NowMotorState,State_t *NextMotorState,State_t*TargetMotorState){
    if(TargetMotorState->direction != NowMotorState->direction){
        __delay_us(20);
        NextMotorState->direction = TargetMotorState->direction;
    }
    if(TargetMotorState->duty > NowMotorState->duty)
        NextMotorState->duty ++;
    if(TargetMotorState->duty < NowMotorState->duty)
        NextMotorState->duty --;
    __delay_us(5);
}
void eusartWriteBit(int b) {
    b = b & 0x01;
    if (b) {
        // Write '1' bit
        GP2 = 1;
        __delay_us(208);        //baud rate = 4800
    } else {
        GP2 = 0;
        __delay_us(208);
    }
}
Пример #29
0
int Leer_Bit(void)
{
	int result=0;
	Pin_BAJO;	// RA4 Baja
        __delay_us(6);  // 6uS espera
	Pin_Entrada;    // Libera RA4 para generar la ventana de de tiempo de lectura
	 __delay_us(6);  // Espera para validar la ventana de lectura
        result = (int)Pin_Lee; // Lee el bus 1-wire
         __delay_us(60);  // Espera para completar la ventana de tiempo
  	return (result);  // Retorna el bit 
}
Пример #30
0
int Reset_1wire(void)
{
	int result=1;
	Pin_BAJO;
        __delay_us(500);  // El pin RA4 baja al menos 480 uS
	Pin_Entrada; 	  // Coloca RA4 como entrada, resit.de 4k7 pone el pin en alto
	__delay_us(60);// Entre 15 y 60uS, DS1820 pone el pin en 0
        result = (int)Pin_Lee; // Lee el estado del pin
	__delay_us(240);// Espera para asegurar el estado del pulso de presencia
        return (result);// 0 = DS1820 Encontrado!!!
}