Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

LCD outputs bad values

Status
Not open for further replies.

Ernestas

Newbie level 4
Newbie level 4
Joined
Oct 5, 2015
Messages
5
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Visit site
Activity points
63
Hello, im trying to make autofeeder for my fishes. I want to make PIC16F628A to work similiar to 555 timer, but with LCD and PWM for food drop rate. So far i made this code


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
// LCD module connections
sbit LCD_RS at RB4_bit;
sbit LCD_EN at RB5_bit;
sbit LCD_D4 at RB0_bit;
sbit LCD_D5 at RB1_bit;
sbit LCD_D6 at RB2_bit;
sbit LCD_D7 at RB6_bit;
 
sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D4_Direction at TRISB0_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D7_Direction at TRISB6_bit;
// End LCD module connections
 
short hour;
short minutes;
char txtVal[] = "Hours :" ;
char txtMin[] = "Minutes :" ;
char txt1[] = "Put hours";
char txt2[] = "Put minutes";
char txt3[5] = "";
char txt4[5] = "";
int Menu = 1;
 
void main() {
 
TRISA = 0b10000000;
TRISB = 0b10000000;
PORTA = 0b00000000;
PCON = 0b00001000;
CMCON = 0b00000111;
Lcd_Init();
 
// welcome message
 
Lcd_Cmd(_LCD_CLEAR);
Lcd_Cmd(_LCD_CURSOR_OFF);
Lcd_Out(1, 3, "Hello");
delay_ms(10000);
Lcd_cmd(_LCD_CLEAR);
 
 
while(RA2 != 1 ){     //RA2 start button
 
switch(Menu){
 
// Hour set in case : 1
 
case 1:  while(Menu == 1){
 
 
ShortToStr(hour, txt3);
Lcd_Out(1, 1, txtVal);         // text: "Hours :"
Lcd_Out(2, 1, txt3);       // show hour value
 
// Increment hour value by 1 until max 12hours
 
if(RA7==1){
hour++;
if(hour==12){
hour = 0;}
};
 
// Change case 1 menu to case 2 menu
 
if(RB7 == 1){
Menu++;
if(Menu == 3){
Menu = 1;
};
};
 };
// Minutes set case : 2
 
case 2: while(Menu == 2){
 
ShortToStr(minutes, txt4);
Lcd_Out(1, 1, txtMin);      // Text "Minutes :"
Lcd_Out(2, 1, txt4);     // Show minutes value
 
// Increment minutes value by 1, until 59
 
if(RA7==1){
minutes++;
if(minutes==59){     // switch back to 0
minutes = 0;}
;}
 
// Change case 2 menu to menu 3 PWM
 
if(RB7 == 1){
Menu++;
if(Menu == 3){
Menu = 1;
};
};
}
 
};
};
}



The problem is that i get hour value -33. Where did i made mistake in code? Thank you.
 
Last edited by a moderator:

You have an unusual program structure but it will probably work.
I thin the problem is that you do not initialize the settings before entering the program loop. Try:
Code:
short hour = 1;
short minutes = 1;
and see if that fixes it.

Brian.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top