|
|
View previous topic :: View next topic |
Author |
Message |
ssaguiar
Joined: 02 Nov 2003 Posts: 11 Location: Brazil
|
Electronic oven program not working |
Posted: Wed Jun 02, 2010 7:44 pm |
|
|
Hi to all.
I am working in the implementation of a firmware for an electronic oven.
It uses the pic16f677.
One big problem is that the circuit has 3 devices attached at each of i/o ports:
1 - seven-segments displays (3).
2 - leds (6).
3 - keys (7).
I just can't find a way to make those devices work together.
I have made the leds and displays work together, but when I added some code for the keys, all results messed up (the display doesn't work
any more and the leds blink at random).
I wish to know if somebody can help me to find a solution for this.
This is the code I have until now:
Code: |
#include "header.h"
/****************************************************************************
* DESCRIPTION: RTCC Interrupt
* RETURN: none
* ALGORITHM: none
* NOTES: none
*****************************************************************************/
#int_rtcc
void Timer0Interrupt ( void )
{
}
/****************************************************************************
* DESCRIPTION: ADC Interrupt
* RETURN: none
* ALGORITHM: none
* NOTES: none
*****************************************************************************/
#int_ad
void adinterrupt (void)
{
cstate = STATE_ADREADY;
}
/****************************************************************************
* DESCRIPTION: Timer 1 Interrupt ISR
* RETURN: none
* ALGORITHM: none
* NOTES: interrupt every 1ms
*****************************************************************************/
#INT_TIMER1
void TIMER1_isr(void)
{
//set_timer1(63536 - get_timer1()); // Restart 1 ms timming
set_timer1(TMR1RESET); // Restart 1 ms timming
if (Timer_1ms++ == 5) // 200 times per second, for the display
{
dispsel++;
Timer_1ms=0;
Timer_10ms++;
cstate = STATE_DISP_SELECT;
if (Timer_10ms == 200) // 1 second?
{
Timer_10ms = 0; // Zero 10 mseconds counter
Timer_1s++; // Incrementa contador de segundos (p/ conversao ad)
if (WAITING == TRUE)
{
output_toggle(LED_OK); // Toggle led on/off
//temper--;
}
}
}
}
/****************************************************************************
* DESCRIPTION: Main program
* RETURN: none
* ALGORITHM: none
* NOTES: none
*****************************************************************************/
void main()
{
setup_oscillator(OSC_8MHZ); // Let's work at 8 MHz clock
SysStart(); // Start system...
while (TRUE) // Do it forever...
{
if (cstate == STATE_DISP_SELECT) // Time to select next display?
{
if (fornoligado == TRUE) // Just when owen ON
{
if (dispsel>2) // If display to show > 2
{
dispsel=0; // Set first display
}
showdigit(dispsel, temper); // Show temperature read in display
}
cstate = STATE_IDDLE; // Return to iddle state
}
if (cstate == STATE_ADREADY) // Is Temperature AD ready?
{
readadc(); // Temperature read
}
if (cstate == STATE_IDDLE) // Time to rest?
{
if (Timer_1s >= 10) // Every 10 seconds
{
Timer_1s = 0; // Reset our seconds counter
set_adc_channel (7); // Select temperature sensor AD
read_adc(ADC_START_ONLY); // Start reading of AD channel
}
}
}
}
/****************************************************************************
* DESCRIPTION: Init all system's units and variables.
* RETURN: none
* ALGORITHM: none
* NOTES: none
*****************************************************************************/
void SysStart (void)
{
char counter;
delay_ms ( 200 ); // Wait enough time after Vdd rise
Timer_1ms = 0; // Reset Timer counters
Timer_100ms = 0; // " " "
Timer_1s = 0; // " " "
Timer_1m = 0; // " " "
temper = TEMPERATURE;
cstate = STATE_IDDLE; // Default state of machine is iddle
fornoligado = TRUE;
key_up = TRUE;
key_dwn = TRUE;
key_temp = TRUE;
key_timer = FALSE;
key_onoff = TRUE;
key_toaster = FALSE;
key_light = FALSE;
temporizador= TEMPOR;
port_a_pullups (FALSE);
port_b_pullups (FALSE);
set_tris_c (0b10000010);
output_high(BUZZER);
setup_comparator (NC_NC_NC_NC);
setup_timer_0 (RTCC_INTERNAL | RTCC_DIV_256 | RTCC_8_BIT);
setup_timer_1 (T1_INTERNAL | T1_DIV_BY_1);
setup_adc_ports (sAN5|sAN9);
setup_adc (ADC_CLOCK_DIV_4);
set_timer1 (TMR1RESET); // Set 1 ms timming
enable_interrupts (INT_TIMER1); // Enable Timer1 interrupt
enable_interrupts (INT_RTCC); // Enable Timer0 interrupt
enable_interrupts (INT_AD); // Enable A/D interrupt
enable_interrupts (GLOBAL); // Enable all interrupts
}
/****************************************************************************
* DESCRIPTION: readadc - read and plot adc data.
* RETURN: none
* ALGORITHM: none
* NOTES: none
*****************************************************************************/
void readadc (void)
{
char counter;
long readadc;
set_adc_channel ( 6 ); // Select ad channel 0 (fuel)
readadc = read_adc(); // Read it
temper = (int)((readadc*100)/1024); // Convert value
}
/****************************************************************************
* DESCRIPTION: Show one digit on display.
* RETURN: none
* ALGORITHM: none
* NOTES: Digits 0 - 2 (LSB, MSB, HSB)
*****************************************************************************/
void showdigit (char digit, char value)
{
char huns, tens, ones, toshow;
huns = value / 100;
tens = ( value - ( huns * 100 ) ) / 10;
ones = value - ( ( huns * 100 ) + ( tens * 10 ) );
port_a_pullups (FALSE);
port_b_pullups (FALSE);
set_tris_c(0b10000010);
output_high (DISPLAY3_EN); // Desliga displays
output_high (DISPLAY2_EN); //
output_high (DISPLAY1_EN); //
output_high(LED_CMN); // Desliga leds
//To display leds:
set_tris_a(0b11001011);
set_tris_b(0b10001111);
tmp = (key_up == TRUE) ? output_low(LED_KEY_UP):output_high(LED_KEY_UP);
tmp = (key_dwn == TRUE) ? output_low(LED_KEY_DWN):output_high(LED_KEY_DWN);
tmp = (key_temp == TRUE) ? output_low(LED_KEY_TEMP):output_high(LED_KEY_TEMP);
tmp = (key_timer == TRUE) ? output_low(LED_KEY_TIMER):output_high(LED_KEY_TIMER);
//tmp = (key_onoff == TRUE) ? output_low(LED_KEY_ONOFF):output_high(LED_KEY_ONOFF);
tmp = (key_toaster == TRUE) ? output_low(LED_KEY_TOASTER):output_high(LED_KEY_TOASTER);
tmp = (key_light == TRUE) ? output_low(LED_KEY_LIGHT):output_high(LED_KEY_LIGHT);
output_low(LED_CMN); // Liga leds
delay_us(100);
output_high(LED_CMN); // Desliga leds
delay_us(100);
switch ( digit )
{
case 0:
toshow = digittbl[ones];
break;
case 1:
toshow = digittbl[tens];
break;
case 2:
toshow = digittbl[huns];
break;
}
output_high (DISPLAY3_EN); // Desliga displays
output_high (DISPLAY2_EN); //
output_high (DISPLAY1_EN); //
//To display digits:
set_tris_a(0b11001011);
set_tris_b(0b00001111);
tmp = bit_test (toshow,6) ? output_high(SEG_A):output_low(SEG_A);
tmp = bit_test (toshow,5) ? output_high(SEG_B):output_low(SEG_B);
tmp = bit_test (toshow,4) ? output_high(SEG_C):output_low(SEG_C);
tmp = bit_test (toshow,3) ? output_high(SEG_D):output_low(SEG_D);
tmp = bit_test (toshow,2) ? output_high(SEG_E):output_low(SEG_E);
tmp = bit_test (toshow,1) ? output_high(SEG_F):output_low(SEG_F);
tmp = bit_test (toshow,0) ? output_high(SEG_G):output_low(SEG_G);
switch (dispsel)
{
case 0:
output_low (PIN_C3);
break;
case 1:
if((huns>0) &&(tens>0))output_low (PIN_C4);
break;
case 2:
if(huns>0) output_low (PIN_C5);
break;
}
//check_keys();
output_high (DISPLAY3_EN); // Desliga displays
output_high (DISPLAY2_EN); //
output_high (DISPLAY1_EN); //
output_high(LED_CMN); // Desliga leds
delay_us(10);
set_tris_a(0b11111111);
set_tris_b(0b11111111);
delay_us(10);
port_a_pullups (FALSE);
port_b_pullups (FALSE);
delay_us(10);
if (input(KEY_UP)==0)
{
if (keyupcnt++ == 20)
{
key_up ^= 1;
temper++;
keyupcnt=0;
}
}
if (input(KEY_DWN)==0)
{
if (keydwncnt++ == 20)
{
key_dwn ^= 1;
temper--;
keydwncnt=0;
}
}
if (input(KEY_TEMP)==0)
{
if (keytempcnt++ == 20)
{
key_temp ^= 1;
keytempcnt=0;
}
}
if (input(KEY_TIMER)==0)
{
if (keytimercnt++ == 20)
{
key_timer ^= 1;
keytimercnt=0;
}
}
if (input(KEY_ONOFF)==0)
{
if (keyonoffcnt++ == 20)
{
key_onoff ^= 1;
keyonoffcnt=0;
}
}
if (input(KEY_TOASTER)==0)
{
if (keytoastercnt++ == 20)
{
key_toaster ^= 1;
keytoastercnt=0;
}
}
if (input(KEY_LIGHT)==0)
{
if (keylightcnt++ == 20)
{
key_light ^= 1;
keylightcnt=0;
}
}
port_a_pullups (FALSE);
port_b_pullups (FALSE);
}
/****************************************************************************
* DESCRIPTION: Check keys.
* RETURN: none
* ALGORITHM: none
* NOTES:
*****************************************************************************/
void check_keys (void)
{
disable_interrupts (INT_TIMER1); // Enable Timer1 interrupt
set_tris_a(0b11111111);
set_tris_b(0b11111111);
set_tris_c(0b10110111);
output_high (PIN_C3); // Liga anodo display (para poder ler teclas)
port_a_pullups (TRUE);
port_b_pullups (TRUE);
if (input(KEY_UP)==0)
{
if (keyupcnt++ == 20)
{
key_up ^= 1;
temper++;
keyupcnt=0;
}
}
if (input(KEY_DWN)==0)
{
if (keydwncnt++ == 20)
{
key_dwn ^= 1;
temper--;
keydwncnt=0;
}
}
if (input(KEY_TEMP)==0)
{
if (keytempcnt++ == 20)
{
key_temp ^= 1;
keytempcnt=0;
}
}
if (input(KEY_TIMER)==0)
{
if (keytimercnt++ == 20)
{
key_timer ^= 1;
keytimercnt=0;
}
}
if (input(KEY_ONOFF)==0)
{
if (keyonoffcnt++ == 20)
{
key_onoff ^= 1;
keyonoffcnt=0;
}
}
if (input(KEY_TOASTER)==0)
{
if (keytoastercnt++ == 20)
{
key_toaster ^= 1;
keytoastercnt=0;
}
}
if (input(KEY_LIGHT)==0)
{
if (keylightcnt++ == 20)
{
key_light ^= 1;
keylightcnt=0;
}
}
enable_interrupts (INT_TIMER1); // Enable Timer1 interrupt
}
|
This is the header file content:
Code: |
/****************************************************************************
* DESCRIPTION: General stuff
* RETURN: none
* ALGORITHM: none
* NOTES: none
*****************************************************************************/
//#include <18F4620.h>
//#include <18F452.h>
//#include <16f877a.h>
#include <16f677.h>
#device ADC=10
#device PASS_STRINGS = IN_RAM
#zero_ram
#case
/****************************************************************************
* DESCRIPTION: Timing stuff (clock and serial)
* RETURN: none
* ALGORITHM: none
* NOTES: none
*****************************************************************************/
#use delay(clock=8000000)
/****************************************************************************
* DESCRIPTION: Fuses
* RETURN: none
* ALGORITHM: none
* NOTES: none
*****************************************************************************/
#FUSES NOWDT // NO Watch Dog Timer
#FUSES INTRC_IO // High speed Osc (> 4mhz)
#FUSES NOPROTECT // Code not protected from reading
#FUSES NOBROWNOUT // No brownout reset
#FUSES PUT // Power Up Timer
#FUSES NOCPD // No EE protection
#FUSES NOMCLR // Master Clear pin disabled
/****************************************************************************
* DESCRIPTION: Includes
* RETURN: none
* ALGORITHM: none
* NOTES: none
*****************************************************************************/
#include <stdlib.h>
/****************************************************************************
* DESCRIPTION: System defines
* RETURN: none
* ALGORITHM: none
* NOTES: none
*****************************************************************************/
#define TICKS_BETWEEN_INTERRUPTS 2000
#define INTERRUPT_OVERHEAD 35
#define TMR1RESET (0xFFFF-(TICKS_BETWEEN_INTERRUPTS-INTERRUPT_OVERHEAD))
/****************************************************************************
* Definições gerais
***************************************************************************/
#define YES 1
#define NO 0
#define ON 1
#define OFF 0
#define TRUE 1
#define FALSE 0
#define PORTA 5
#define PORTB 6
#define PORTC 7
/****************************************************************************
* Definição para o sensor de temperatura
***************************************************************************/
#define SENSOR_TEMP PIN_C3
/****************************************************************************
* Definição para as teclas
***************************************************************************/
#define KEY_UP PIN_B7
#define KEY_DWN PIN_A2
#define KEY_TEMP PIN_A3
#define KEY_TIMER PIN_B6
#define KEY_ONOFF PIN_B5
#define KEY_TOASTER PIN_A5
#define KEY_LIGHT PIN_B4
/****************************************************************************
* Definição para os leds
***************************************************************************/
#define LED_KEY_UP PIN_B4
#define LED_KEY_DWN PIN_A2
#define LED_KEY_TEMP PIN_B5
#define LED_KEY_TIMER PIN_B6
#define LED_KEY_ONOFF PIN_C6
#define LED_KEY_TOASTER PIN_A5
#define LED_KEY_LIGHT PIN_B4
/****************************************************************************
* Definição acionamento dos elementos do display
***************************************************************************/
#define DISPLAY1_EN PIN_C5
#define DISPLAY2_EN PIN_C4
#define DISPLAY3_EN PIN_C3
/****************************************************************************
* Definição acionamento dos leds
***************************************************************************/
#define LED_CMN PIN_C2
/****************************************************************************
* Definição acionamento segmentos dos displays
***************************************************************************/
#define SEG_A PIN_A2
#define SEG_B PIN_A5
#define SEG_C PIN_B7
#define SEG_D PIN_B5
#define SEG_E PIN_A4
#define SEG_F PIN_B6
#define SEG_G PIN_B4
#define LSD 0
#define MSD 1
#define HSD 2
#define TEMPERATURE 180
#define TEMPOR 40
#define WAITING TRUE
#define LED_OK PIN_C6
#define LED_BUZ PIN_B6
#define LED_SYS PIN_A3
#define LED_TABLE_LENGTH 20
#define BUZZER PIN_C0
//#bit BUZZER = PORTC.0
/****************************************************************************
* DESCRIPTION: Define Variables
* RETURN: none
* ALGORITHM: none
* NOTES: none
*****************************************************************************/
int Timer_1ms, Timer_10ms, Timer_100ms, Timer_1s, Timer_1m;
char temper, temporizador, tmp;
char cstate, dispsel;
char keyupcnt, keydwncnt, keytempcnt, keytimercnt, keyonoffcnt, keytoastercnt, keylightcnt;
int1 fornoligado, key_up, key_dwn, key_temp, key_timer, key_onoff, key_toaster, key_light;
int1 timeforkeys;
enum
{
STATE_IDDLE,
STATE_LEDS,
STATE_ADREADY,
STATE_DISP_SELECT
};
char const digittbl[10]=
{
0b00000001, //0
0b01001111, //1
0b00010010, //2
0b00000110, //3
0b01001100, //4
0b00100100, //5
0b00100000, //6
0b00001111, //7
0b00000000, //8
0b00001100 //9
};
/****************************************************************************
* DESCRIPTION: Functions Prototypes
* RETURN: none
* ALGORITHM: none
* NOTES: none
*****************************************************************************/
void readadc (void);
void SysStart (void);
void showdigit (char digit, char value);
void check_keys (void);
|
And, finally, this is the part of the circuit which gives me the crips:
http://www.ssaguiar.com/Esquema.JPG |
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Thu Jun 03, 2010 1:36 am |
|
|
In my opinion, you should do two things:
- Design a simple and clear scheme by pencil and paper method how the different activities in your program should be scheduled. I don't think, that you need other interrupts than the periodic timer tic.
- Organize the code according to this scheme. Now it's very confuse, e.g. reading keys in the "showdigit()" function.
I don't think, that you should have state dependant code in the main function. Just call all sub tasks periodically. All task functions are required to return after a maximum amount of time, e.g a few ms. Then "simultaneous" execution of all tasks can be assured. |
|
|
ssaguiar
Joined: 02 Nov 2003 Posts: 11 Location: Brazil
|
|
Posted: Thu Jun 03, 2010 8:18 am |
|
|
Thanks FvM.
I will try to do the way you are indicating.
The major problem is that the original ciruit is somehow messy.
I think that the manufacturer could have used another processor so the digits, keys and leds didn't have to be spread in porta, portb and portc.
Thanks again. |
|
|
rnielsen
Joined: 23 Sep 2003 Posts: 852 Location: Utah
|
|
Posted: Thu Jun 03, 2010 8:37 am |
|
|
Just one quick thing, set_tris() will do nothing unless #use fast_io is also declared.
Ronald |
|
|
ssaguiar
Joined: 02 Nov 2003 Posts: 11 Location: Brazil
|
|
Posted: Thu Jun 03, 2010 11:30 am |
|
|
Hi and thanks for your help.
I made some mods, as indicated by our friends rnielsen and FvM.
I just can't make keys work as expected.
I want to make this:
- if one key is pressed once, increase or decrease the temperature in display.
- if the key is still pressed after 2 seconds, enter the auto-increment state (2 per second).
- also, at this moment, when a key is pressed, the display goes blank untill the key is released
The code, at this moment, is:
Code: |
/*****************************************************************************
**** ****
*****************************************************************************/
#include "header.h"
/****************************************************************************
* DESCRIPTION: RTCC Interrupt
* RETURN: none
* ALGORITHM: none
* NOTES: none
*****************************************************************************/
#int_rtcc
void Timer0Interrupt ( void )
{
//Not used, untill now...
}
/****************************************************************************
* DESCRIPTION: ADC Interrupt
* RETURN: none
* ALGORITHM: none
* NOTES: none
*****************************************************************************/
#int_ad
void adinterrupt (void)
{
adready = TRUE;
}
/****************************************************************************
* DESCRIPTION: Timer 1 Interrupt ISR
* Overflow: 1/((FHz/4)/T1_Divider) = 1/(2000000/1) = 1/2000000 = 0,0000005s=0.5us.
* If timer1 is preloaded with 65535 = Overflow = 0.5us * 65536 = 0,032768 s.
* For an overflow of 1ms:
* 0,001 = 0,0000005 * X
* X = 0,001/0,0000005 => X = 2000
* For an overflow of 1ms, preload Timer1 with: 65536-63536, wich is: 2000.
* Thus:
* f(interrupt)=1/(freq_cpu/4/prescaler/preloadvalue)
* As I want one interrupt at every 1 ms:
* f(interrupt)=1/(8000000/4/1/2000)
* f(interrupt)= 1000 times/second => T(f) = 1/f = 0,001 (1 ms).
* RETURN: none
* ALGORITHM: none
* NOTES: interrupt every 1ms
*****************************************************************************/
#INT_TIMER1
void TIMER1_isr(void)
{
set_timer1(63536 - get_timer1()); // Restart 1 ms timming
if (Timer_1ms++ == 10) // 10 ms?
{
Timer_1ms=0;
Timer_10ms++;
if (Timer_10ms == 50) // 0.5 second?
{
if (WAITING == TRUE) // Only blink if waiting for a command.
{
output_toggle(LED_OK); // Toggle led on/off
}
Timer_10ms = 0;
}
}
}
/****************************************************************************
* DESCRIPTION: Main program
* RETURN: none
* ALGORITHM: none
* NOTES: none
*****************************************************************************/
void main()
{
setup_oscillator(OSC_8MHZ); // Let's work at 8 MHz clock
SysStart(); // Start system...
while (TRUE) // Do it forever...
{
if (fornoligado == TRUE) // Just when oven ON
{
showdigit(temper); // Show temperature read in display
showleds(); // Show leds state
check_keys();
if (cooking ==TRUE) // If cooking
{
if (adready == TRUE)
{
readadc(); // Temperature read & process
set_adc_channel (7); // Select temperature sensor AD
read_adc(ADC_START_ONLY);// Start reading AD channel
}
//showtimer(); // Show timer
}
}
}
}
/****************************************************************************
* DESCRIPTION: Init all system's units and variables.
* RETURN: none
* ALGORITHM: none
* NOTES: none
*****************************************************************************/
void SysStart (void)
{
char counter;
delay_ms ( 200 ); // Wait enough time after Vdd rise
Timer_1ms = 0; // Reset Timer counters
Timer_100ms = 0; // " " "
Timer_1s = 0; // " " "
Timer_1m = 0; // " " "
temper = TEMPERATURE;
fornoligado = TRUE;
key_up = TRUE;
key_dwn = TRUE;
key_temp = TRUE;
key_timer = FALSE;
key_onoff = TRUE;
key_toaster = FALSE;
key_light = FALSE;
temporizador= TEMPOR;
#use fast_io(A)
#use fast_io(B)
#use fast_io(C)
port_a_pullups (TRUE);
port_b_pullups (TRUE);
set_tris_c (0b10000010);
output_high(BUZZER);
setup_comparator (NC_NC_NC_NC);
setup_timer_0 (RTCC_INTERNAL | RTCC_DIV_256 | RTCC_8_BIT);
setup_timer_1 (T1_INTERNAL | T1_DIV_BY_1);
setup_adc_ports (sAN5|sAN9);
setup_adc (ADC_CLOCK_DIV_4);
set_timer1 (63536 - get_timer1()); // Restart 1 ms timming
enable_interrupts (INT_TIMER1); // Enable Timer1 interrupt
enable_interrupts (INT_RTCC); // Enable Timer0 interrupt
enable_interrupts (INT_AD); // Enable A/D interrupt
enable_interrupts (GLOBAL); // Enable all interrupts
}
/****************************************************************************
* DESCRIPTION: readadc - read and plot adc data.
* RETURN: none
* ALGORITHM: none
* NOTES: none
*****************************************************************************/
void readadc (void)
{
char counter;
long readadc;
set_adc_channel ( 6 ); // Select ad channel 7
readadc = read_adc(); // Read it
temper = (int)((readadc*100)/1024); // Convert value
}
/****************************************************************************
* DESCRIPTION: Show one digit on display.
* RETURN: none
* ALGORITHM: none
* NOTES: Digits 0 - 2 (LSB, MSB, HSB)
*****************************************************************************/
void showdigit (char value)
{
char huns, tens, ones, toshow;
huns = value / 100;
tens = ( value - ( huns * 100 ) ) / 10;
ones = value - ( ( huns * 100 ) + ( tens * 10 ) );
if (dispsel++ >2) // If display to show > 2
{
dispsel=0; // Set first display
}
set_tris_c(0b10000010);
switch ( dispsel )
{
case 0:
toshow = digittbl[ones];
break;
case 1:
toshow = digittbl[tens];
break;
case 2:
toshow = digittbl[huns];
break;
}
output_high (DISPLAY3_EN); // Turn off displays
output_high (DISPLAY2_EN); //
output_high (DISPLAY1_EN); //
output_high(LED_CMN); // Turn off leds
//To display digits:
set_tris_a(0b11001011);
set_tris_b(0b00001111);
tmp = bit_test (toshow,6) ? output_high(SEG_A):output_low(SEG_A);
tmp = bit_test (toshow,5) ? output_high(SEG_B):output_low(SEG_B);
tmp = bit_test (toshow,4) ? output_high(SEG_C):output_low(SEG_C);
tmp = bit_test (toshow,3) ? output_high(SEG_D):output_low(SEG_D);
tmp = bit_test (toshow,2) ? output_high(SEG_E):output_low(SEG_E);
tmp = bit_test (toshow,1) ? output_high(SEG_F):output_low(SEG_F);
tmp = bit_test (toshow,0) ? output_high(SEG_G):output_low(SEG_G);
switch (dispsel)
{
case 0:
output_low (PIN_C3);
break;
case 1:
((huns==0)&&(tens==0)) ? output_high (PIN_C4):output_low(PIN_C4);
break;
case 2:
(huns>0) ? output_low (PIN_C5):output_high (PIN_C5);
break;
}
delay_us(100);
}
/****************************************************************************
* DESCRIPTION: readadc - read and plot adc data.
* RETURN: none
* ALGORITHM: none
* NOTES: none
*****************************************************************************/
void showleds(void)
{
output_high (DISPLAY3_EN); // Turn off displays
output_high (DISPLAY2_EN); //
output_high (DISPLAY1_EN); //
//To display leds:
set_tris_a(0b11001011);
set_tris_b(0b10001111);
tmp = (key_up == TRUE) ? output_low(LED_KEY_UP):output_high(LED_KEY_UP);
tmp = (key_dwn == TRUE) ? output_low(LED_KEY_DWN):output_high(LED_KEY_DWN);
tmp = (key_temp == TRUE) ? output_low(LED_KEY_TEMP):output_high(LED_KEY_TEMP);
tmp = (key_timer == TRUE) ? output_low(LED_KEY_TIMER):output_high(LED_KEY_TIMER);
//tmp = (key_onoff == TRUE) ? output_low(LED_KEY_ONOFF):output_high(LED_KEY_ONOFF);
tmp = (key_toaster == TRUE) ? output_low(LED_KEY_TOASTER):output_high(LED_KEY_TOASTER);
tmp = (key_light == TRUE) ? output_low(LED_KEY_LIGHT):output_high(LED_KEY_LIGHT);
output_low(LED_CMN); // Leds on
delay_us(100); // Wait a little bit...
}
/****************************************************************************
* DESCRIPTION: Check keys.
* RETURN: none
* ALGORITHM: none
* NOTES:
*****************************************************************************/
void check_keys (void)
{
set_tris_a(0b00110100);// 11111111); // Make keys inputs
set_tris_b(0b11110000);// 11111111); // ' ' '
//port_a_pullups (TRUE);
//port_b_pullups (TRUE);
//output_low (DISPLAY3_EN); // Turn on one display
if (input(KEY_UP)==0)
{
delay_ms(250);
if (keyupcnt++ == 2)
{
key_up ^= 1;
temper++;
keyupcnt=0;
}
}
if (input(KEY_DWN)==0)
{
delay_ms(250);
if (keydwncnt++ == 2)
{
key_dwn ^= 1;
temper--;
keydwncnt=0;
}
}
if (input(KEY_TEMP)==0)
{
delay_ms(250);
if (keytempcnt++ == 2)
{
key_temp ^= 1;
keytempcnt=0;
}
}
if (input(KEY_TIMER)==0)
{
delay_ms(250);
if (keytimercnt++ == 2)
{
key_timer ^= 1;
keytimercnt=0;
}
}
if (input(KEY_ONOFF)==0)
{
delay_ms(250);
if (keyonoffcnt++ == 2)
{
key_onoff ^= 1;
keyonoffcnt=0;
}
}
if (input(KEY_TOASTER)==0)
{
delay_ms(250);
if (keytoastercnt++ == 2)
{
key_toaster ^= 1;
keytoastercnt=0;
}
}
if (input(KEY_LIGHT)==0)
{
delay_ms(250);
if (keylightcnt++ == 2)
{
key_light ^= 1;
keylightcnt=0;
}
}
port_a_pullups (FALSE);
port_b_pullups (FALSE);
}
/*****************************************************************************
*****************************************************************************/
/*
;---------------------------------------------------
beep:
;---------------------------------------------------
movlw d'150'
movwf lbcnt
bploop bsf porta,b_beeper
Wait 500 Microsec,0
bcf porta,b_beeper
Wait 500 Microsec,0
decfsz lbcnt,F
goto bploop
return
;---------------------------------------------------
beep2:
;---------------------------------------------------
movlw d'150'
movwf lbcnt
bploop2 bsf porta,b_beeper
Wait 250 Microsec,0
bcf porta,b_beeper
Wait 250 Microsec,0
decfsz lbcnt,F
goto bploop2
return
playsnd bsf porta,b_beeper
psloop Wait 500 Microsec,0
bcf porta,b_beeper
Wait 500 Microsec,0
decfsz lbcnt,F
goto psloop
return
*/
|
|
|
|
ssaguiar
Joined: 02 Nov 2003 Posts: 11 Location: Brazil
|
|
Posted: Fri Jun 04, 2010 8:48 am |
|
|
Nobody?
Please, I need, if possible, that someone just give a clue on a way to make the keys being read.
Thanks |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
ssaguiar
Joined: 02 Nov 2003 Posts: 11 Location: Brazil
|
|
Posted: Fri Jun 04, 2010 2:45 pm |
|
|
Thank you PCM programmer, I will give a look. |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|