Switch to Linear ModeSwitch to Hybrid ModeSwitch to Threaded Mode
Printer Friendly View | Email this page | Register Now to enjoy user benefits!
Chizuru
Chizuru's Avatar
不存在
Join Date: Mar 2008
Posts: 141
Trade rep: 100%
URGENTLY need someone to help me debug my program Chizuru Aug 6th, 09, 02:11 PM #1 (permalink)
My C language program requires the target board to start counting once it is turned on. There are 2 switches and 2 push buttons, RA5, RE0, RE1, and RE2 respectively. I'm required to set different timings for each of the switches/buttons and trigger an audio and visual signal. (RA0, RA1, RA2, and RA3 are LEDs and RA4 is the buzzer. PORTC is connected to the 7 segment display which shows how many buttons are currently counting down.

here's my program

Quote:
#include <p18f4520.h>
#include <delays.h>

void Init_LCD(void); //initialize the lcd
void W_ctr_8bit(char); //8 bit control word for lcd
void W_data_8bit(char); //8 bit text data for lcd
void time(void); //time display format
void switchprogram(void); //program for switches
void 7segment(void);


int h = 0; //initialize hour
int m = 0; //initialize minute
int s = 0; //initialize seconds
int loop = 1; //for counting through looping
int 7segnumber = 0; //initialize 7seg number

int fifteen = 0; //individual loops for timing
int five = 0;
int ten = 0;
int twenty = 0;

char counting[9] = "COUNTING";
char count;

void main()
{
ADCON1 = 0x0F; //set to digital
TRISC = 0; //set PORTD as output
TRISB = 0b00111000; //set PORTB as output
TRISD = 0; //set PORTC as output
TRISA = 0b11100000;
TRISE=0b11111111;
PORTC = 0b11111111;//turn off 7 segment, use 1 to off (com anode)
PORTAbits.RA0 = 0; //turn off LED's initially
PORTAbits.RA1 = 0;
PORTAbits.RA2 = 0;
PORTAbits.RA3 = 0;

for(loop!=0;loop++)
{
time();
W_ctr_8bit(0b00000111);
W_data_8bit(count);
s++;

if(s==60)
{
m++;
s = 0;
}


switchprogram();

7segment();

Delay10KTCYx(50); //1 second count

}

} //main program ends here

void time()
{
for(h>=10) //displays a 0 in front when the hour number is single
{
count = "0"+h+":"+m;
}
for(m>=10) //displays a 0 in front when the minute number is single
{
count = +h+":0"+m;
}
for(h>=10&&m>=10) //displays a 0 in front of both when both numbers are single
{
count = "0"+h+":0"+m;
}
for(m>=60) //changes 60minutes into 1 hour
{
h++;
m = 0;
}
}


void Init_LCD()
{
W_ctr_8bit(0b00111100); //function set 8 bit 2 lines
W_ctr_8bit(0b00001100); //display on cursor on
W_ctr_8bit(0b00000110); //entry mode - inc addr, no shift
W_ctr_8bit(0b00000001); //clear display and home position
W_ctr_8bit(0x02);
}

void W_ctr_8bit(char x)
{
LCD_RS = 0;
LCD_E = 1;
LCD_DATA = x;
LCD_E = 0;
Delay_1kcyc();
}

void W_data_8bit(char x)
{
LCD_RS = 1;
LCD_E = 1;
LCD_DATA = x;
LCD_E = 0;
Delay_1kcyc();
}

void switchprogram()
{
if(PORTAbits.RA5==0) //sw1 for 15min count
{
7segnumber++;
for(fifteen==0;fifteen<900;fifteen++) //looping for 15mins
{
if(fifteen==900)
{
7segnumber--;
PORTAbits.RA4=1; //sounds buzzer
PORTAbits.RA0=1; //activates led
PORTAbits.RA1=1;
PORTAbits.RA2=1;
PORTAbits.RA3=1;
fifteen = 0;
Delay100TCYx(5);
break;
}
}
}

if(PORTEbits.RE0==0) //sw3 for 5min count
{
7segnumber++;
for(five==0;five<300;five++) //looping for 5mins
{
if(five==300)
{
7segnumber--;
PORTAbits.RA4=1; //sounds buzzer
PORTAbits.RA0=1; //activates led
PORTAbits.RA1=1;
PORTAbits.RA2=1;
PORTAbits.RA3=1;
five = 0;
Delay100TCYx(5);
break;
}
}
}

if(PORTEbits.RE1==0) //sw2 for 10min count
{
7segnumber++;
for(ten==0;ten<600;ten++) //looping for 10mins
{
if(ten==600)
{
7segnumber--;
PORTAbits.RA4=1; //sounds buzzer
PORTAbits.RA0=1; //activates led
PORTAbits.RA1=1;
PORTAbits.RA2=1;
PORTAbits.RA3=1;
ten = 0;
Delay100TCYx(5);
break;
}
}
}


if(PORTEbits.RE2==0) //sw4 for 20min count
{
7segnumber++;
for(twenty==0;twenty<1200;twenty++) //looping for 20mins
{
if(twenty==1200)
{
7segnumber--;
PORTAbits.RA4=1; //sounds buzzer
PORTAbits.RA0=1; //activates led
PORTAbits.RA1=1;
PORTAbits.RA2=1;
PORTAbits.RA3=1;
twenty = 0;
Delay100TCYx(5);
break;
}
}
}
}

void 7segment();
{
switch(7segnumber)
{
case 0 : PORTC = 0b01111111; break; // logic '0' to turn on the 7 segment. a is at the right, g is at the left starting from the second one. PORTC = 0b0gfedcba;
case 1 : PORTC = 0b01111001; break;
case 2 : PORTC = 0b00100100; break;
case 3 : PORTC = 0b00110000; break;
case 4 : PORTC = 0b00011001; break;
}
}
Gotta submit this tomorrow ): the teacher has been really unhelpful. Not wanting to teach us anything and expecting us to research on the internet.




Arguing on the internet is like running in the Special Olympics .Even if you win, you're still retarded.
 
Last edited by Chizuru; Aug 6th, 09 at 02:46 PM..
Chizuru
Chizuru's Avatar
不存在
Join Date: Mar 2008
Posts: 141
Trade rep: 100%
Chizuru Aug 6th, 09, 05:15 PM #2 (permalink)
the main problem with the program is I need to display two digits when displaying the time. like 00:00 or 01:10




Arguing on the internet is like running in the Special Olympics .Even if you win, you're still retarded.
 
proyb2 Veni, vidi, vici
Join Date: Jun 2005
Posts: 11,612
Trade rep: 50%
proyb2 Aug 7th, 09, 09:28 PM #3 (permalink)
how do you post this at the last min? The program is as simple as in English, how is it difficult to program?

I could see
for(five==0;five<300;five++)
which should have been a single (assign operator) = instead, the == has become a comparison logic instead, so this might be the issue?
Veni, vidi, vici "I came, I saw, I conquered."

A lot of people are afraid of heights. Not me. I'm afraid of widths.
 
Last edited by proyb2; Aug 7th, 09 at 09:30 PM..
New Thread | ↑↓ Similar Threads
Similar Threads Thread Starter Forum Replies Last Post
newzhunter News around the web! 4 Apr 26th, 08
12:19 AM
dotaman Troubleshooting Zone/Technical Enquiries 0 Jan 15th, 08
04:36 PM
myfootsmells Overclocking Bazaar 2 Oct 30th, 06
08:14 PM
=SniPa= Networking & Broadband 7 Jul 27th, 03
05:18 PM
Thread Tools Display Modes
Linear Mode Linear Mode
Find the best hotel rates here:
Destination:

City:

Check in Date:


Nights:
Rooms:
Adult(s):
Children:
travel.vr-zone.com
OCZ Fan Club!
OCZ Fan Club 21 OCZ Fans!
Win Visa GiftCard
Win Visa Gift Card