SugarD Guest
|
18F65J90 and weird behavior |
Posted: Wed Dec 23, 2009 8:41 pm |
|
|
Code: |
//main.c
#include<18F65J90.h>
#include<def_18F65J90.h>
#fuses intrc
//Define keys
#define key1 portg3
#define key2 porta3
#define key3 porta2
#define key4 porta0
#use delay(clock = 32000)
#define clock_speed 32000
#define DIGIT1 COM0+0, COM2+31, COM3+31, COM1+31, COM0+31, COM1+0, COM2+0, COM3+0
const int8 DIGIT_MAP[28]= {0x3F, 0x06, 0x5B, 0x4F, 0x66, 0x6D, 0x7D, 0x27, 0x7F, 0x67
,0X00, 0X77, 0x7C, 0x39, 0x5E, 0X79, 0X71, 0X04, 0X38, 0X54
,0X5C, 0X73, 0X50, 0X6d, 0X78, 0X1C, 0X3e, 0X40};
void LCD_init(void){
LCDPS = 0b0010100; //WFT = 0(Type A waveform), BIASMD = 0(1/4 bias),
//LCDA = 1(lcd drive module is active), WA = 1(write allowed), LP = 0000(prescaling = 8:1)
//LCDSEx definition
LCDSE0 = 0xFF; //SEG<7:0> All Segment control
LCDSE1 = 0B10011111; //SEG<15:8> do not use 11(pulse_out)
LCDSE2 = 0XFF; //SEG<23:16> All segment control
LCDSE3 = 0B11011101; //SEG<31:24>
LCDSE4 = 0B00000001;
//LCDCON setup
LCDCON = 0b10011011; // LCDEN = 1, /SLPEN = 1, WERR = 0,unimplemented, CS<1:0> = 00(Fosc/4), LMUX<1:0> = 11(use 4 commons)
LCDREG = 0B00111100;//Unemplemented, CPEN = 0, BIAS<2:0> = 111, MODE13 = 1, CKSEL<1:0> = 00(regulator disabled)s
}
void init_rtn(void){
lcd_init();
trisg3 = 1;
trisa3 = 1;
trisa2 = 1;
trisa0 = 1;
}
void main(void){
int8 buffer;
init_rtn();
//2-1
while(1){
if(key1) lcd_symbol(digit_map[1], digit1);
else lcd_symbol(digit_map[EMPTY], digit1);
}
}
|
I was checking the connection of 4 keys which are connected to port g3, a3, a2, and a0.
I am using ICD3 debugger and watch window (watching registers PORTG and PORTA)
to see if the keys are working alright.
When I tested the code with the debugger I could see that only key1 is recognized to be on.
Weirdly, when I replace
Code: |
while(1){
if(key1) lcd_symbol(digit_map[1], digit1);
else lcd_symbol(digit_map[EMPTY], digit1);
}
|
with just
I no longer can see key 1 working anymore.
My compiler version is 4.103
Thanks |
|