Sesion 11 A 13
Sesion 11 A 13
Sesion 11 A 13
CCS PARA
MICROCONTROLADORES
PIC
// Keypad layout:
char
const
KEYS[4][4]
{{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}};
#define
KBD_DEBOUNCE_FACTOR
33
// Set this number to apx n/333
where
// n is the
number of times you expect
void kbd_init() {
}
char kbd_getc( ) {
static byte kbd_call_count;
static short int kbd_down;
static char last_key;
static byte col;
byte kchar;
byte row;
kchar='\0';
if(++kbd_call_count>KBD_DEBOUNCE_FACTOR)
{
switch (col) {
case 0 : set_tris_kbd(ALL_PINS&~COL0);
kbd=~COL0&ALL_PINS;
break;
case 1 : set_tris_kbd(ALL_PINS&~COL1);
kbd=~COL1&ALL_PINS;
break;
case 2 : set_tris_kbd(ALL_PINS&~COL2);
kbd=~COL2&ALL_PINS;
break;
case 3 : set_tris_kbd(ALL_PINS&~COL3);
kbd=~COL3&ALL_PINS;
break;
}
EULER DEZA FIGUEROA
Euler_df28@hotmail.com
if(kbd_down) {
if((kbd
&
(ALL_ROWS))==(ALL_ROW
S)) {
kbd_down=false;
kchar=last_key;
last_key='\0';
}
}
else {
kbd_call_count=0;
}
set_tris_kbd(ALL_PINS);
return(kchar);
}
Librera: lcd.c
#if defined(__PCB__)
LCD_PIN_MAP lcd, lcdlat;
#byte lcd = LCD_DATA_PORT
#byte lcdlat = LCD_DATA_PORT
#elif defined(__PCM__)
LCD_PIN_MAP lcd, lcdlat, lcdtris;
#byte lcd = LCD_DATA_PORT
#byte lcdlat = LCD_DATA_PORT
#byte lcdtris = LCD_DATA_PORT+0x80
#elif defined(__PCH__)
LCD_PIN_MAP lcd, lcdlat, lcdtris;
#byte lcd = LCD_DATA_PORT
#byte lcdlat = LCD_DATA_PORT+9
#byte lcdtris = LCD_DATA_PORT+0x12
#elif defined(__PCD__)
LCD_PIN_MAP lcd, lcdlat, lcdtris;
#word lcd = LCD_DATA_PORT
#word lcdlat = LCD_DATA_PORT+2
#word lcdtris = LCD_DATA_PORT-0x02
#endif
#endif //LCD_DATA4 not defined
#ifndef LCD_TYPE
#define LCD_TYPE 2
#endif
#ifndef LCD_LINE_TWO
#define LCD_LINE_TWO 0x40
line
#endif
BYTE lcd_read_byte(void)
{
BYTE low,high;
#if defined(__PCB__)
set_tris_lcd(LCD_INPUT_MAP);
#else
#if (defined(LCD_DATA4) && defined(LCD_DATA5)
&& defined(LCD_DATA6) && defined(LCD_DATA7))
output_float(LCD_DATA4);
output_float(LCD_DATA5);
output_float(LCD_DATA6);
output_float(LCD_DATA7);
#else
lcdtris.data = 0xF;
#endif
#endif
lcd_output_rw(1);
delay_cycles(1);
lcd_output_enable(1);
delay_cycles(1);
high = lcd_read_nibble();
Librera: lcd.c
lcd_output_enable(0);
delay_cycles(1);
lcd_output_enable(1);
delay_us(1);
low = lcd_read_nibble();
lcd_output_enable(0);
#if defined(__PCB__)
set_tris_lcd(LCD_INPUT_MAP);
#else
#if
(defined(LCD_DATA4)
defined(LCD_DATA5)
defined(LCD_DATA6)
defined(LCD_DATA7))
output_drive(LCD_DATA4);
output_drive(LCD_DATA5);
output_drive(LCD_DATA6);
output_drive(LCD_DATA7);
#else
lcdtris.data = 0x0;
#endif
#endif
return( (high<<4) | low);
}
&&
&&
&&
Librera: lcd.c
void lcd_send_nibble(BYTE n)
{
#if
(defined(LCD_DATA4)
&&
defined(LCD_DATA5)
&&
defined(LCD_DATA6)
&&
defined(LCD_DATA7))
/* Write to the data port */
output_bit(LCD_DATA4, bit_test(n, 0));
output_bit(LCD_DATA5, bit_test(n, 1));
output_bit(LCD_DATA6, bit_test(n, 2));
output_bit(LCD_DATA7, bit_test(n, 3));
#else
lcdlat.data = n;
#endif
delay_cycles(1);
lcd_output_enable(1);
delay_us(2);
lcd_output_enable(0);
}
TOBE.
Bibliografa
CCS C Compiler Manual PCD CCS INC FEBREO 2015
CCS C Compiler Manual PCB/PCM/PCH CCS INC FEBREO
2015
Compilador C CCS y simulador PROTEUS para
Microcontroladores PIC Eduardo Garca Breijo
Diseo y simulacion de Sistemas microcontrolados en lenguaje
C Juan Ricardo Clavijo Mendoza
Programacion en CCS para Microcontroladores PIC Aaron
Castro Bazua
Datasheets