firmware/user.c
changeset 25 96f051df5d60
parent 2 2f55e5dd591d
equal deleted inserted replaced
24:8fede80bde19 25:96f051df5d60
    84 unsigned char	gg_keys;
    84 unsigned char	gg_keys;
    85 unsigned char	gg_ioflags;
    85 unsigned char	gg_ioflags;
    86 unsigned char	gg_pwm1dc	= 0x00;
    86 unsigned char	gg_pwm1dc	= 0x00;
    87 unsigned char	gg_mode		= MODE_UNMANAGED;
    87 unsigned char	gg_mode		= MODE_UNMANAGED;
    88 
    88 
       
    89 unsigned char	ee_display;
       
    90 unsigned char	ee_features;
       
    91 
    89 unsigned char	nKeys1, nKeys2;
    92 unsigned char	nKeys1, nKeys2;
    90 unsigned char	oKeys1, oKeys2;
    93 unsigned char	oKeys1, oKeys2;
    91 unsigned char	dKeys1, dKeys2;
    94 unsigned char	dKeys1, dKeys2;
    92 unsigned char	bKeys1;
    95 unsigned char	bKeys1;
    93 
    96 
   108 	TRISE	= 0x00;
   111 	TRISE	= 0x00;
   109 	TRISB	= 0x00; 	PORTB	= 0xFF;
   112 	TRISB	= 0x00; 	PORTB	= 0xFF;
   110 	// make sure, PC wont start...
   113 	// make sure, PC wont start...
   111 	PIN_POWER	= 0;
   114 	PIN_POWER	= 0;
   112 
   115 
       
   116 	// read saved settings
       
   117 	ee_display 		= Read_b_eep (EE_ADDR_DISPLAY);
       
   118 	ee_features		= Read_b_eep (EE_ADDR_FEATURES);
       
   119 
   113 
   120 
   114 	// reset INT settings...
   121 	// reset INT settings...
   115 	INTCON			= 0x00;	// first disable all ints..
   122 	INTCON			= 0x00;	// first disable all ints..
   116 	PIE1			= 0x00; // and also all perephial ints
   123 	PIE1			= 0x00; // and also all perephial ints
   117 	PIE2			= 0x00;
   124 	PIE2			= 0x00;
   131 
   138 
   132 	// portB interrupts (i2c_int on RB5)
   139 	// portB interrupts (i2c_int on RB5)
   133 	INTCON2bits.RBIP	= 0;	//make this a low-priority-interrupt
   140 	INTCON2bits.RBIP	= 0;	//make this a low-priority-interrupt
   134 	PIN_I2C_INT			= 1;	//switch pin to high-level (doesnt really work.. its an open collector. BUT i've got pullups)
   141 	PIN_I2C_INT			= 1;	//switch pin to high-level (doesnt really work.. its an open collector. BUT i've got pullups)
   135 	DDR_I2C_INT			= 1;	//woo woo! this one has to be an input, for interrupts to work
   142 	DDR_I2C_INT			= 1;	//woo woo! this one has to be an input, for interrupts to work
   136 	nKeys1 				= 0xFF - LDByteReadI2C(pcf8574A_1);		// make sure to reset i2c_int... just in case...
   143 	if (ee_features && 0x01)
   137 	oKeys1				= nKeys1;
   144 	{
   138 	nKeys2				= 0xFF - LDByteReadI2C(pcf8574A_2);
   145 		nKeys1 				= 0xFF - LDByteReadI2C(pcf8574A_1);		// make sure to reset i2c_int... just in case...
   139 	oKeys2				= nKeys2;
   146 		oKeys1				= nKeys1;
       
   147 		nKeys2				= 0xFF - LDByteReadI2C(pcf8574A_2);
       
   148 		oKeys2				= nKeys2;
       
   149 	}
   140 	INTCONbits.RBIF		= 0;	// then clear the flag!
   150 	INTCONbits.RBIF		= 0;	// then clear the flag!
   141 	INTCONbits.RBIE		= 1;	// Activate PortB interrupts
   151 	INTCONbits.RBIE		= 1;	// Activate PortB interrupts
   142 
   152 
   143 
   153 
   144 	// enable alarm
   154 	// enable alarm
   145 	LDByteWriteI2C(pcf8583,0x00,0x04);
   155 	if (ee_features && 0x00)
       
   156 	{
       
   157 		LDByteWriteI2C(pcf8583,0x00,0x04);
       
   158 	}
   146 
   159 
   147 
   160 
   148 	// Timer3 acts as 'event-ticker'
   161 	// Timer3 acts as 'event-ticker'
   149 	WriteTimer3(0x0000);
   162 	WriteTimer3(0x0000);
   150 	OpenTimer3(TIMER_INT_ON & T3_16BIT_RW & T3_PS_1_8 & T3_SYNC_EXT_OFF & T3_SOURCE_INT);
   163 	OpenTimer3(TIMER_INT_ON & T3_16BIT_RW & T3_PS_1_8 & T3_SYNC_EXT_OFF & T3_SOURCE_INT);
   179 	// reset flags
   192 	// reset flags
   180 	gg_ioflags = FLAG_CLEAR;
   193 	gg_ioflags = FLAG_CLEAR;
   181 
   194 
   182 
   195 
   183 	// init & clear Display
   196 	// init & clear Display
   184 	lcd_InitDisplay();			
   197 	if (ee_display)
   185 	lcd_InitDisplay();			// ugly workaround...
   198 	{
       
   199 		lcd_InitDisplay();			
       
   200 		lcd_InitDisplay();			// ugly workaround...
       
   201 	}
   186 }//end UserInit
   202 }//end UserInit
   187 
   203 
   188 
   204 
   189 
   205 
   190 void Wstring (char *dat,unsigned char len)
   206 void Wstring (char *dat,unsigned char len)