示例#1
0
void LCD_init(void)
{
	unsigned char inits[7] = {0x33, 0x32, 0x28, 0x01, 0x0c, 0x06, 0x00};
	unsigned char temp;
	char i;
	
	TRISD &= 0b00001111;	//set high nibble of portd to output
	RS_SIG = 0;
	E_SIG = 0;
	E_TRIS = 0;
	RS_TRIS = 0;
	
	memset(lcdtext, ' ', sizeof(lcdtext)-1);
	Delay10KTCYx(25);
	
	for( i = 0; i < 7; i++ )
	{
		E_SIG = 1;
		temp = inits[i];
		temp &= 0b11110000;
		LATD &= 0b00001111;
		LATD |= temp;
		E_SIG = 0;
		Delay1KTCYx(25);
		E_SIG = 1;
		temp = inits[i] << 4;
		temp &= 0b11110000;
		LATD &= 0b00001111;
		LATD |= temp;
		E_SIG = 0;
		Delay1KTCYx(25);
	}	
	
}	
void LCD_w(unsigned char a)
{

	unsigned char cs = SPI_CUR_SEL;
	unsigned char ret=1;
	if(cs == SPI_LCD) {
		SPI_Device_Select(SPI_MEM);
		Delay1KTCYx(1);
	}
	while(ret) {
		SPI_Device_Select(SPI_LCD);
		Delay1KTCYx(1);
		ret = rw_spi_byte(MAX3100_WRITE);
		if(ret & 64) {
			rw_spi_byte(a);
			ret = 0;
		} else
			ret = 1;
		if(cs != SPI_LCD)
			SPI_Device_Select(cs);
		else
			SPI_Device_Select(SPI_GPS);
	}
	
}
示例#3
0
文件: main.c 项目: Sel2016/microchip
void piscaVermelho (void){
    LED2=1;
        Delay1KTCYx(15);
    LED2=0;
        Delay1KTCYx(85);
    
}
void config_SPI_devs(void)
{
	char a = 0;
	if(SPI_CUR_SEL == 0) {
		SPI_Device_Select(1);
		Delay1KTCYx(10);
	}
	for(a=0;a<4;a++) {
		
		SPI_Device_Select(a);
		Delay1KTCYx(10);
		switch(a) {
			case SPI_GPS:
			rw_spi_byte(MAX3100_WCONFIGR);
			rw_spi_byte(UART_4800);
			break;
		case SPI_UART:
			rw_spi_byte(MAX3100_WCONFIG);
			rw_spi_byte(UART_115200); 
			break;
		case SPI_LCD:
			rw_spi_byte(MAX3100_WCONFIG);
			rw_spi_byte(UART_9600);
			break;
		case SPI_MEM:
			rw_spi_byte(MAX3100_WCONFIG);
			rw_spi_byte(UART_9600); //Change Speed Later
			break;
		default:
			Nop();
			break;
		}
	}
	SPI_Device_Select(SPI_GPS); //Unselect last device to let config take place
}
示例#5
0
文件: main.c 项目: korbah/manticord
void HeartBeat(void)
{
    ACT_LED_01 = 0;
    Delay1KTCYx(100);
    ACT_LED_01 = 1;
    Delay1KTCYx(100);

    WriteUSART('#'); // :
    while (BusyUSART());
}
示例#6
0
文件: lcd.c 项目: sektor1986/PULT_MTZ
void OpenXLCD(unsigned char lcdtype)
{
// 4-bit mode
#ifdef UPPER                            // Upper 4-bits of the port
	DATA_PORT &= 0x0f;
	TRIS_DATA_PORT &= 0x0F;
#else                                   // Lower 4-bits of the port
	DATA_PORT &= 0xf0;
	TRIS_DATA_PORT &= 0xF0;
#endif
	TRIS_RW = 0;                    // All control signals made outputs
	TRIS_RS = 0;
	TRIS_E = 0;
	RW_PIN = 0;                     // R/W pin made low
	RS_PIN = 0;                     // Register select pin made low
	E_PIN = 0;                      // Clock pin made low

	// Delay for 15ms to allow for LCD Power on reset
	DelayPORXLCD();
 //-------------------reset procedure through software----------------------       
	WriteCmdXLCD(0x30);
	Delay1KTCYx(33);

	WriteCmdXLCD(0x30);
	Delay1KTCYx(0x01);


	WriteCmdXLCD(0x32);
	while( BusyXLCD() );
//------------------------------------------------------------------------------------------

	// Set data interface width, # lines, font
	while(BusyXLCD());              // Wait if LCD busy
	WriteCmdXLCD(lcdtype);          // Function set cmd

	// Turn the display on then off
	while(BusyXLCD());              // Wait if LCD busy
	WriteCmdXLCD(DOFF&CURSOR_OFF&BLINK_OFF);        // Display OFF/Blink OFF
	while(BusyXLCD());              // Wait if LCD busy
	WriteCmdXLCD(DON&CURSOR_ON&BLINK_ON);           // Display ON/Blink ON

	// Clear display
	while(BusyXLCD());              // Wait if LCD busy
	WriteCmdXLCD(0x01);             // Clear display

	// Set entry mode inc, no shift
	while(BusyXLCD());              // Wait if LCD busy
	WriteCmdXLCD(SHIFT_CUR_LEFT);   // Entry Mode

	// Set DD Ram address to 0
	while(BusyXLCD());              // Wait if LCD busy
	SetDDRamAddr(0x80);                // Set Display data ram address to 0

	return;
}
示例#7
0
void sendTest() {
    Write1USART(Test[0]);
    Delay1KTCYx(4);
    Write1USART(Test[1]);
    Delay1KTCYx(4);
    Write1USART(Test[2]);
    Delay1KTCYx(4);
    Write1USART(Test[3]);
    Delay1KTCYx(4);
    Write1USART('\n');
}
示例#8
0
/*******************************************************************************
* PUBLIC FUNCTION: delay_ms
*
* PARAMETERS:
* ~ ui_millisecond
*
* RETURN:
* ~ void
*
* DESCRIPTIONS:
* delay for for period millisecond base on ui_millisecond
* based on _XTAL_FREQ value, ui_millisecond range from 0-65,535.
*******************************************************************************/
void delay_ms(unsigned int ui_millisecond)
{
	for( ; ui_millisecond > 0; ui_millisecond --)
	{
		#if (_XTAL_FREQ == 20000000)
		Delay1KTCYx(5);	//5K instruction cycle with 20MHz oscillator is 1ms
		#elif (_XTAL_FREQ == 48000000)
		Delay1KTCYx(12);	//12K instruction cycle with 48MHz oscillator is 1ms
		#endif
	}		
}	
void delayms(int x){
    if (MNML){
        Delay1KTCYx(x);
        Delay1KTCYx(x);
        Delay1KTCYx(x);

    }
    else{
        Delay1KTCYx(x);
        
    }
}
示例#10
0
void sendAccel()
{
    Write1USART(accArr[0]);
    Delay1KTCYx(4);
    Write1USART('.');
    Delay1KTCYx(4);
    Write1USART(accArr[1]);
    Delay1KTCYx(4);
    Write1USART(accArr[2]);
    Delay1KTCYx(4);
    Write1USART('\n');
}
示例#11
0
void Init_LCD(void)
{
LCD_CMD(0x02);	 //Dat che do giao tiep 4-bit, man hinh 2 dong
Delay1KTCYx(1);
LCD_CMD(0x28);	 //Tat man hinh
Delay1KTCYx(1);
LCD_CMD(0x0C);	 //Che do nhap du lieu binh thuong
Delay1KTCYx(1);
LCD_CMD(0x06 );	 //Bat man hinh, hien con tro nhap nhay
Delay1KTCYx(1);
//LCD_CMD(0x01);	 //Xoa man hinh
Delay1KTCYx(1);
}
char GPS_r(void)
{

	unsigned char cs	= SPI_CUR_SEL;
	unsigned char ret;
	char gval;
	if(cs == SPI_GPS) {
		SPI_Device_Select(SPI_MEM);
		Delay1KTCYx(1);
	}
	
	SPI_Device_Select(SPI_GPS);
	ret = rw_spi_byte(MAX3100_READ);
	if(ret & READ_READY) {
		gval = rw_spi_byte(0);
	} else
		gval = 0;
	if(cs != SPI_GPS)
		SPI_Device_Select(cs);
	else
		SPI_Device_Select(SPI_MEM);
			
	return gval;
	
}
示例#13
0
// only called from "main"
void block_on_To_msgqueues()
{
	if (!in_main()) {
		return;
	}
	//LATBbits.LATB3 = 1;
	MQ_Main_Willing_to_block = 1;
	while (1) {
		if (check_msg(&ToMainHigh_MQ)) {
			MQ_Main_Willing_to_block = 0;
			//LATBbits.LATB3 = 0;
			return;
		}
		if (check_msg(&ToMainLow_MQ)) {
			MQ_Main_Willing_to_block = 0;
			//LATBbits.LATB3 = 0;
			return;
		}
		if (check_msg(&adReadQueue))
		{
			MQ_Main_Willing_to_block = 0;
			//LATBbits.LATB3 = 0;
			return;
		}
		Delay1KTCYx(10);
		//LATBbits.LATB3 = !LATBbits.LATB3;
	}
}
示例#14
0
//main function
void main(void)
{
    unsigned char st1[]="STARTING";
    unsigned char st2[]=".";

    //pins for drive LCD
    TRISB = 0x80;

    //Initialize modules
    Init_LCD();
    i2c_config();

    set_ds1307_time(AM,0,0,6);
    set_ds1307_day(8,11,8,13);

    lcd_putstr(st1);

    for(i=0;i<7;i++)
    {
        lcd_putstr(st2);
        Delay1KTCYx(200);
    }
    LCD_CMD(LCD_clear);
    
    while(1)
    {
        lcd_gotoxy(1,1);//hang 1, cot 1.
        Display_time(get_ds1307_time());

        lcd_gotoxy(1,2);//hang 2, cot 1
        Display_day(get_ds1307_day());

        Delay10KTCYx(70);
    };
}
void main (void)
{
    OSCCON            = 0x60;       // IRCFx = 110
    OSCTUNEbits.PLLEN = 0;          // x4 PLL disabled

    // Port D used for diagnostic LEDs
    TRISD      = 0b00111111;     // PORTD bit 7 to output (0) ; bits 6:0 are inputs (1)
    LATDbits.LATD7 = 0;             // RED LED 
    LATDbits.LATD6 = 0;             // YLW LED 
        
    // Setup MSSP in 7 bit I2C Slave mode
    TRISC          = 0b00011000;    // TRISC 3&4 (SCL & SDA) inputs
    LATC           = 0b00011000;
    SSPADD         = I2C_ADDR;      // Set I2C address
    SSPCON1        = 0x36;          // SSPEN: Synchronous Serial Port Enable bit - Enables the serial port and configures the SDA and SCL pins as the serial port pins
                                    // CKP: SCK Release Control bit              - Release clock
                                    // SSPM3:SSPM0: SSP Mode Select bits         - 0110 = I2C Slave mode, 7-bit address    
    SSPSTAT        = 0x00;
    SSPCON2        = 0x01;          // GCEN: General Call address (00h) (Slave mode only) 0 = General call address disabled
                                    // SEN: Start Condition Enable/Stretch Enable bit(1) ()Slave mode) 1 = Clock stretching is enabled 
    PIR1bits.SSPIF = 0;             // Clear MSSP interrupt request flag
    PIE1bits.SSPIE = 1;             // Enable MSSP interrupt enable bit
    INTCONbits.GIE_GIEH  = 1;       // GIE/GIEH: Global Interrupt Enable bit
    INTCONbits.PEIE_GIEL = 1;       // PEIE/GIEL: Peripheral Interrupt Enable bit

    while (1)
    {
        Delay1KTCYx(50);    // Delay 50 x 1000 = 50,000 cycles; 200ms @ 1MHz
    }    
}
示例#16
0
void Delay15ms(void) {
    Delay1KTCYx(180); // Delay of 15ms
    // Cycles = (TimeDelay * Fosc) / 4
    // Cycles = (15ms * 8MHz) / 4
    // Cycles = 30,000
    return;
}
示例#17
0
void main(void)
{
	//timer vars
	int result;
	float final_result;

	Delay100TCYx(10); //let the device startup
	usart_init();
	i2c_init();
	printf("Starting\r\n");


	// let sonar initialize, delay 250 ms
	Delay1KTCYx(625);
	TRISBbits.TRISB3 = 1;	// data pin input
	
	while(1)
	{
		while(PORTBbits.RB3 == 0);
		// configure timer0
		OpenTimer0(TIMER_INT_OFF & T0_16BIT & T0_SOURCE_INT & T0_PS_1_1);
 		WriteTimer0( 0 );         // restart timer
		while(PORTBbits.RB3 == 1);
		//Delay1TCY();
		result = ReadTimer0();    // read timer
		printf("Timer is %u \r\n", result);
		final_result = (float)result / (float)(2.5*147);
		printf("X / (4*147) = %i \r\n", (int)final_result);
		
	}
	
}
示例#18
0
void Delay5ms(void) {
    Delay1KTCYx(60); // Delay of 5ms
    // Cycles = (TimeDelay * Fosc) / 4
    // Cycles = (5ms * 8MHz) / 4
    // Cycles = 10,000
    return;
}
示例#19
0
/******************************************************************************
 * R_EEPROM subroutine
 * 
 * This routine will read the last set of data from EEPROM and save that data
 *  into holding registers in RAM for tranmission across USART.
 * 
 * Inputs:      addr = EEPROM memory address for pulling data from
 *              mem = RAM location to write data to
 * Outputs:     None
 ******************************************************************************/
void R_EEPROM(unsigned short long addr, unsigned char * mem) {
    unsigned char temp;
    unsigned char i;
    unsigned char high;
    unsigned char med;
    unsigned char low;

    high = addr>>16;                    //High byte of EEPROM memory location
    med = addr>>8;                      //Medium byte of EEPROM memory location
    low = addr;                         //Low byte of EEPROM memory location
    
    EEPROMEnable();                     //Pull CS low to write
    WriteSPI(ReadEEPROM);               //Set READ on EEPROM
    
    WriteSPI(high);                     //Send high address to EEPROM
    WriteSPI(med);                      //Send medium address to EEPROM
    WriteSPI(low);                      //Send low address to EEPROM
    
    for (i = 0; i < 30; i++) {
        temp = WriteSPI(0x00);          //Save the data to holding location in RAM
        mem[i] = temp;
    }
    EEPROMDisable();                    //Push CS high to deselect EEPROM
    Delay1KTCYx(1);                    //Wait for read to finish just in case
}
示例#20
0
void block_on_To_msgqueues() {
    if (!in_main()) {
        return;
    }
#ifdef __USE18F2680
    LATBbits.LATB3 = 1;
#endif
    MQ_Main_Willing_to_block = 1;
    while (1) {
        if (check_msg(&ToMainHigh_MQ)) {
            MQ_Main_Willing_to_block = 0;
#ifdef __USE18F2680
            LATBbits.LATB3 = 0;
#endif
            return;
        }
        if (check_msg(&ToMainLow_MQ)) {
            MQ_Main_Willing_to_block = 0;
#ifdef __USE18F2680
            LATBbits.LATB3 = 0;
#endif
            return;
        }
        Delay1KTCYx(10);
#ifdef __USE18F2680
        LATBbits.LATB3 = !LATBbits.LATB3;
#endif
    }
}
void Open_nRF24L01_SPI (void)
{
	unsigned char result;

	SPI_CSN_TRIS = 0;
	SPI_CE_TRIS	= 0;
	SPI_IRQ_TRIS = 1;
	SPI_SO_TRIS = 0;
	SPI_SCK_TRIS = 0;
	
	SPI_CE = 1;
	SPI_CSN = 1;

	OpenSPI(SPI_FOSC_4, MODE_00, SMPMID); //open SPI1
	
	Delay1KTCYx(3);

	result = Test_SPI();
	if (result)
	{
		LED_ON
		while (1);				// se retornou 1 é porque tem falha comunicação c/ SPi
	}

	configure_Radio();

}//
示例#22
0
/**********************************
* WaitHalfSec: Delay for 0.5 seconds
***********************************/
void WaitHalfSec(void)
{
    int Halfcount = 50;			// Load count for 0.5 sec using 10 ms delay
    while (Halfcount != 0)
    {
            Delay1KTCYx(25);		// Use delay function for 10 ms count
            Halfcount = Halfcount-1;	// Decrement 0.5 sec count
    }
}
示例#23
0
//-----------Chuong trinh con nhay den cot x, dong y-------------------------------------------------------------------
void lcd_gotoxy(int x, int y)
{
	int address;
	if(y != 1) address = lcd_line_two;
	else address=0;
	address += x-1;
	LCD_CMD(0x80|address);
	Delay1KTCYx(2);
}
示例#24
0
void LCD_delay_ms(unsigned char time) {

    unsigned char i;
    time = time * 20;
    for (i = 0; i < time; i++) {
        Delay1KTCYx(60); //(1/(20MHZ / 4 )) = 200us
    }
    return; //200us * 1000  = 200ms * 1 = 200ms
}
示例#25
0
void LCD_data(unsigned char data){
    LCD_isbusy();
    RS = HIGH;
    RW = LOW;
    EN = HIGH;
    DATAPORT = data;
    Delay1KTCYx(50);
    EN = LOW;
}
示例#26
0
void LCD_cmd(unsigned char cmd){
    LCD_isbusy();
    RS = LOW;
    RW = LOW;
    EN = HIGH;
    DATAPORT = cmd;
    Delay1KTCYx(50);
    EN = LOW;
}	
示例#27
0
void lcd_putstr(char *buffer)
{
	while(*buffer != '\0')
	{
		LCD_DATA(*buffer); /* calling another function */
		/* to write each char to the lcd module */
		buffer++;
		Delay1KTCYx(2);
	};
}
示例#28
0
文件: suiveurP.c 项目: 7Robot/PIC
///// Définition des fonctions du programme. /////
void DelayMS(int delay)
{
    /*Attente en ms, sur cette carte c'est utile, et vu que le Quart est soudé,
     il y a peu de raisons pour que ça change...*/
    int cp = 0;
    for(cp=0; cp<delay; cp++)
    {
        Delay1KTCYx(5);
    }
}
示例#29
0
文件: main.c 项目: Sel2016/microchip
 void DelayXLCD(void)     // minimum 5ms
 {
 //Delay100TCYx(0x36);      // 100TCY * 54

 Delay1KTCYx(5); 	// Delay of 5 ms
						// Cycles = (TimeDelay * Fosc)/4
						// Cycles = (5ms * 4MHz)/4
						// Cycles = 5,000
 return;
 }
示例#30
0
void DelayXLCD( void )
{
// Wait more than 4.1ms 
// 4.1ms> 49200 =  (48000000 x 0.0041)/4 cycles at 48MHz (Use 60000 cycles to be sure)
Delay1KTCYx(60); 	//Delay of 4.1ms
					// Cycles = (TimeDelay * Fosc) / 4
					// Cycles = (4.1ms * 48MHz) / 4
					// Cycles = 50,000
return;
}