anybody can check my program

Status
Not open for further replies.

sonic05

Member level 1
Joined
Mar 14, 2010
Messages
32
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,288
Location
Manila
Activity points
1,580
please help me...


#include <16F877A.h>
#fuses XT,NOWDT,PUT,NOBROWNOUT,NOLVP
#use delay(clock = 4000000)
#byte PORTA=0X05
#byte PORTC=0x07
#byte PORTB=0X06
#define A0 PIN_A0
#define A1 PIN_A1
#define A2 PIN_A2
#define A3 PIN_A3
#define A4 PIN_A4
#define A5 PIN_A5

#define E1 PIN_E1

int sec1,sec2,min1,min2,hour1,hour2;
int secs1,secs2,mins1,mins2,hours1,hours2;
int num1=5,num2=5,num3=5;



int counter=125;
int flag=0;


const int table[10]={0b00111111,
0b00000110,
0b01011011,
0b01001111,
0b01100110,
0b01101101,
0b01111101,
0b00000111,
0b01111111,
0b01101111};



void main()
{
PORTB=0X00;
PORTC=0X00;


set_tris_a(0xff);
set_tris_c(0x00);
set_tris_b(0x00);
set_RTCC(6);
setup_counters(RTCC_INTERNAL,RTCC_DIV_32);
enable_interrupts (INT_RTCC);
enable_interrupts (GLOBAL);

for(;
{
PORTB=table[sec1];
PORTC=0X01;
delay_ms(15);

PORTB=table[sec2];
PORTC=0x02;
delay_ms(15);

PORTB=table[min1];
PORTC=0x04;
delay_ms(15);

PORTB=table[min2];
PORTC=0x08;
delay_ms(15);

PORTB=table[hour1];
PORTC=0x10;
delay_ms(15);

PORTB=table[hour2];
PORTC=0x20;
delay_ms(15);

if(flag==1){


flag=0;

if(input(A4)==1)
{
disable_interrupts(INT_RTCC);

if(input(A2)==1) { --num1; }
if(num1==0){
if(++min1>9) {
min1=0;
if(++min2>5) { min2=0; }
}
num1=5;
}
if(input(A3)==1){ --num2; }

if(num2==0)

{
if( ++hour1>9 )
{
hour1=0;
++hour2;
}
if( (hour2==1) & (hour1==3) ) {
hour1=1;
hour2=0;
}
num2=5;
}


if(input(A1)==1) { --num3; }
if(num3==0){
if(++sec1>9) {
sec1=0;
if(++sec2>5) { sec2=0; }
}
num3=5;
}
}



else if(input(A4)==0){
enable_interrupts(INT_RTCC);
}


///////////////////////////////////////////////////////////im not sure in this part
if(input(E1)==1)
{
disable_interrupts(INT_RTCC);

if(input(A2)==1) { --num1; }
if(num1==0){
if(++mins1>9) {
mins1=0;
if(++mins2>5) { mins2=0; }
}
num1=5;
}
if(input(A3)==1){ --num2; }

if(num2==0)

{
if( ++hours1>9 )
{
hours1=0;
++hours2;
}
if( (hours2==2) & (hours1==4) ) {
hours1=1;
hours2=0;
}
num2=5;
}


if(input(A1)==1) { --num3; }
if(num3==0){
if(++secs1>9) {
secs1=0;
if(++secs2>5) { secs2=0; }
}
num3=5;
}
}



else if(input(E1)==0){
enable_interrupts(INT_RTCC);
}
}

}
}

#int_RTCC
microII()
{ //void switch_time();
if(input(A5)==0)

{
if(--counter>0)return;
counter=125;
flag=1;


if(++sec1>9){
sec1=0;

if(++sec2>5){
sec2=0;

if(++min1>9){
min1=0;

if(++min2>5){
min2=0;
if( ++hour1>9 )
{
hour1=0;
++hour2;
}
if( (hour2==1) & (hour1==3) ) {
sec1=0;
sec2=0;
min1=0;
min2=0;
hour1=1;
hour2=0;

}

///////////////////////////////////////////////////////////and also here...
else if
(input(A5)==1)

{

if(--counter>0)return;
counter=125;
flag=1;

if(++secs1>9){
sec1=0;

if(++secs2>5){
sec2=0;

if(++mins1>9){
min1=0;

if(++mins2>5){
min2=0;
if( ++hours1>9 )
{
hours1=0;
++hours2;
}
if( (hours2==2) & (hours1==4) ) {
secs1=0;
secs2=0;
mins1=0;
mins2=0;
hours1=0;


}
}
}
}
}
}
}
}
}
}
}
}


in this program...if i press PIN_A5 the program of 24 hours will run but if not the program of 12 hours will run..but it still not working but when i remove all the part that im not sure the program of 12hours clock will run..

and can you please help me also to make a program for stopwatch and assign a designated switch..?
 
Last edited:

Do you have the pin configuration of your h/w i mean if you are using 7 segment how it is connected to portb.
 

i used led but it is like a 7segment common cathode...all positive connected to PORT B while all negative connected to PORT C...do you have a yahoo messenger?

---------- Post added at 14:33 ---------- Previous post was at 14:31 ----------

a(0x01)
b(0x02)
c(0x04)
d(0x08)
e(0x10)
f(0x20)
g(0x40)
 
Last edited:

No I dont have yahoo messenger. I will make the code but first i need to study it properly.
 

I have not simulated the program but the scan of LEDs takes 6 x 15mS (=90mS) to complete which is far too slow. The display will flicker badly. Try changing the 15mS delays to 2mS or even 1mS.

Brian.
 

what is the use of Port A.
 

port A are connected to 4switch

---------- Post added at 15:30 ---------- Previous post was at 15:28 ----------

**broken link removed**


you can also see my scheamatic in this site,..the 1st schematic is my circuit that i make but i change something because i used common cathode,...you can see in second schematic how the transistor connected in 7segment common cathode
 

That means Port a is for adjusting sec , min , hour, & mode.
 

#include <16F877A.h>
#fuses XT,NOWDT,PUT,NOBROWNOUT,NOLVP
#use delay(clock = 4000000)
#byte PORTA=0X05
#byte PORTC=0x07
#byte PORTB=0X06
#define A0 PIN_A0
#define A1 PIN_A1


#define A3 PIN_A3
#define A4 PIN_A4



int sec1,sec2,min1,min2,hour1,hour2;
int secs1,secs2,mins1,mins2,hours1,hours2;
int num1=5,num2=5,num3=5;



int counter=125;
int flag=0;

----------------------------------look up----------
const int table[10]={0b00111111,
0b00000110,
0b01011011,
0b01001111,
0b01100110,
0b01101101,
0b01111101,
0b00000111,
0b01111111,
0b01101111};



void main()
{

-------------------o/p---
PORTB=0X00;
PORTC=0X00;
----------------
-------------------i/p---
PORTA=0XFF;
--------------

set_tris_a(0xff);
set_tris_c(0x00);
set_tris_b(0x00);

---------------register init---------
set_RTCC(6);
setup_counters(RTCC_INTERNAL,RTCC_DIV_32);
enable_interrupts (INT_RTCC);
enable_interrupts (GLOBAL);
------------------------------------

------------ift lp--------------
for(;
{
----===Skip 1st time----

---- accessing look up table-----------
PORTB=table[sec1];
PORTC=0X01;
delay_ms(8);
PORTB=table[sec2];
PORTC=0x02;
delay_ms(8);

PORTB=table[min1];
PORTC=0x04;
delay_ms(8);

PORTB=table[min2];
PORTC=0x08;
delay_ms(8);

PORTB=table[hour1];
PORTC=0x10;
delay_ms(8);

PORTB=table[hour2];
PORTC=0x20;
delay_ms(8);
------------------------------------
------------------------------------


-------------------------------------12 hr


--------------skip & go to [1] for general configuration (reset)----------------
if(flag==1){

flag=0;

---------------------a0: min, a1: hr, a3: sec, a4: mode

if(input(A4)==1)
{
disable_interrupts(INT_RTCC);

---------------------------------
if(input(A0)==1) { --num1; }
if(num1==0){
if(++min1>9) {
min1=0;
if(++min2>5) { min2=0; }-----max min:59
}
num1=5;
}-----------min f--------------



if(input(A1)==1){ --num2; }

if(num2==0)

{
if( ++hour1>9 )
{
hour1=0;
++hour2;
}
if( (hour2==1) & (hour1==3) ) {
hour1=1;
hour2=0;
}------------------max hr: 12
num2=5;
}-------------------------------hr f


if(input(A3)==1) { --num3; }
if(num3==0){
if(++sec1>9) {
sec1=0;
if(++sec2>5) { sec2=0; }
}-------------------------max sec 59---
num3=5;
}
}---------- sec f

---------------0x004------------

else if(input(A4)==0){
enable_interrupts(INT_RTCC);
}


--------------------------------
-------------------------------------24 hr
-------------------------------


if(input(A4)==1)
{
disable_interrupts(INT_RTCC);

---------------------------------
if(input(A0)==1) { --num1; }
if(num1==0){
if(++mins1>9) {
mins1=0;
if(++mins2>5) { mins2=0; }
}
num1=5;-----------------------max min:59
}
------min f
-------------------------------
if(input(A1)==1){ --num2; }

if(num2==0)

{
if( ++hours1>9 )
{
hours1=0;
++hours2;
}
if( (hours2==2) & (hours1==4) ) {
hours1=1;
hours2=0;
}
num2=5;------------------------max hr: 24
}
------hr f

-----------------------------
if(input(A2)==1) { --num3; }
if(num3==0){
if(++secs1>9) {
secs1=0;
if(++secs2>5) { secs2=0; }
}
num3=5;--------------------------max sec: 59
}
}
------------sec f---


else if(input(A4)==0){
enable_interrupts(INT_RTCC);
}
}

}
}

------------------------------------------[1]--


----------------------------------0x004

#int_RTCC
microII()
{ //void switch_time();


--------------------- for 12 hr

if(input(A4)==0)
{
if(--counter>0)return;
counter=125;
flag=1;


if(++sec1>9){
sec1=0;

if(++sec2>5){
sec2=0;

if(++min1>9){
min1=0;

if(++min2>5){
min2=0;
if( ++hour1>9 )
{
hour1=0;
++hour2;
}
if( (hour2==1) & (hour1==3) ) {
sec1=0;
sec2=0;
min1=0;
min2=0;
hour1=1;
hour2=0;

}

--------------------- for 24 hr
else if
(input(A4)==1)

{

if(--counter>0)return;
counter=125;
flag=1;

if(++secs1>9){
sec1=0;

if(++secs2>5){
sec2=0;

if(++mins1>9){
min1=0;

if(++mins2>5){
min2=0;
if( ++hours1>9 )
{
hours1=0;
++hours2;
}
if( (hours2==2) & (hours1==4) ) {
secs1=0;
secs2=0;
mins1=0;
mins2=0;
hours1=0;


}
}
}
}
}
}
}
}
}
}
}
}
 

yes...but i dont know if it will run...

im not sure for those part of 24hrs but when i used only the 12hours programs it will run...but for 24 hours nothing happen...can you please help me..

to build a program...for that...or i have some option here

1st....12hrsclock with stopwatch

or 12hrs clock that can become a 24hrs...what do you think?
 

I have made small modification in i/p configuration as a0: min, a1: hr, a3: sec, a4: mode.

Now just change the h/w confg compile and simulate the code I hope it will run if it is giving still problem then betwn function of 12 & 24 hr use some nop.
 

but can you please help me for some part of a program?
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…