View previous topic :: View next topic |
Author |
Message |
HTAluvBeBeo
Joined: 23 Feb 2008 Posts: 35
|
need help with 74595. Very urgent, thx |
Posted: Fri May 09, 2008 12:44 pm |
|
|
Code: | #include <16F877A.h>
#include <def_877a.h>
#FUSES NOWDT, HS, NOPUT, NOPROTECT, NODEBUG, BROWNOUT, NOLVP, NOCPD, NOWRT
#use delay(clock=20000000)
#define data PIN_A0 // pin 14
#define latch595 PIN_A1 // pin 12
#define clk PIN_A2 // pin 11
int8 led1,led2,led3,led4,led5,led6;
int8 const led7ac[10] = {0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90};
int1 blink,blink_led1,blink_led2,blink_led3,blink_led4,blink_led5,blink_led6,led_off;
int8 count_display;
void latch(void);
void send595(int8 temp);
void display();
void main(){
setup_adc(adc_off);
setup_adc_ports(NO_ANALOGS);
trisa=0x00;
blink=0;blink_led1=0;blink_led2=0;blink_led3=0;blink_led4=0;blink_led5=0;blink_led6=0;led_off=0;
count_display=20;
led1=1;
led2=2;
led3=3;
led4=4;
led5=5;
led6=8;
while(1)
{
display();
}
}
void send595(int8 temp) {
int8 i;
for(i=0;i<8;i++)
{
if((temp&0x80)!=0)
output_high(data); //bit 1
else output_low(data); //bit 0
delay_cycles(1);
output_high(clk);
delay_cycles(1);
output_low(clk);
temp=temp<<1;
}
}
void latch(void)
{delay_cycles(1);
output_high(latch595);
delay_cycles(1);
output_low(latch595);
}
void display(){
TRISB=0X00;TRISA=0X00;
if(blink==0)goto normal;
if(led_off==1) goto blink_off;
////////////////////////////////////////////////////////////////////////////////
normal: //////////NORMAL MODE//////////////////////
PortB=led7ac[led1]; send595(0x01);latch();//on
delay_ms(4); send595(0x00);latch();//off
PortB=led7ac[led2]; send595(0x02);latch();//on
delay_ms(4); send595(0x00);latch();//off
PortB=led7ac[led3]; send595(0x04);latch();//on
delay_ms(4);send595(0x00);latch();//off
PortB=led7ac[led4]; send595(0x08);latch();//on
delay_ms(4); send595(0x00);latch();//off
PortB=led7ac[led5]; send595(0x10);latch();//on
delay_ms(4); send595(0x00);latch();RA1=0;//off
PortB=led7ac[led6]; send595(0x20);latch();
delay_ms(4); send595(0x00);latch();//off
////////////////////////////////////////////////////////////////////////////////
if(count_display!=0) goto exit_display;
else{
count_display=20;
led_off=1;
}
goto exit_display;
////////////////////////////////////////////////////////////////////////////////
blink_off: ///////////BLINK MODE//////////////////////
PortB=led7ac[led1];
if(blink_led1==1) {send595(0x00);latch();}//off if blink
else {send595(0x01);latch();}//on if not
delay_ms(4); send595(0x00);latch();//off
PortB=led7ac[led2];
if(blink_led2==1) {send595(0x00);latch();}//off if blink
else {send595(0x02);latch();}
delay_ms(4); send595(0x00);latch();//off
PortB=led7ac[led3];
if(blink_led3==1) {send595(0x00);latch();}//off if blink
else {send595(0x04);latch();}//on if not
delay_ms(4); send595(0x00);latch();//off
PortB=led7ac[led4];
if(blink_led4==1) {send595(0x00);latch();}//off if blink
else {send595(0x08);latch();}
delay_ms(4); send595(0x00);latch();//off
PortB=led7ac[led5];
if(blink_led5==1) {send595(0x00);latch();}//off if blink
else {send595(0x10);latch();}//on if not
delay_ms(4); send595(0x00);latch();//off
PortB=led7ac[led6];
if(blink_led6==1) {send595(0x00);latch();}//off if blink
else {send595(0x20);latch();}
delay_ms(4); send595(0x00);latch();//off
if(count_display==0){count_display=20;led_off=0;}
exit_display:
count_display--;
}
|
I did some test. But it did not work. PLz help me
Last edited by HTAluvBeBeo on Sun May 11, 2008 9:42 am; edited 4 times in total |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
HTAluvBeBeo
Joined: 23 Feb 2008 Posts: 35
|
|
Posted: Fri May 09, 2008 3:09 pm |
|
|
I am not allowed to use code library from ccs. It is a requirement of this project :( Poor me
Could you check my code please. That is only a couple of lines
THX so much |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri May 09, 2008 3:59 pm |
|
|
Quote: |
#define data ra0 // pin 14
#define latch ra1 // pin 12
#define clk ra2 // pin 11
|
What is "ra0" ? That's not a CCS pin number.
You should use the pin constants listed in the 16F877A.H file.
Example:
Code: | #define DATA PIN_A0 |
|
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Fri May 09, 2008 4:13 pm |
|
|
The CCS compiler has several modes for handling the I/O pins, default is standard_io mode. Read the CCS manual chapter on '#use standard_io' for more info on how this affects the TRIS register.
How did you connect the 74595 pins OE (13) and SCLR (10) ?
Which 74xx family are you using? LS, HC, HCT, etc?
What is the maximum clock frequency for this chip?
How many instructions per second does a 20MHz PIC perform?
From the answers to the above questions my guess is you can do with a lot less delay instructions.
Hint: check the logic level for the latch signal. |
|
|
HTAluvBeBeo
Joined: 23 Feb 2008 Posts: 35
|
|
Posted: Fri May 09, 2008 8:32 pm |
|
|
PCM: I wrote a definition file .h to define PINs of PIC
.............
#bit RA5 =0x05.5
#bit RA4 =0x05.4
#bit RA3 =0x05.3
#bit RA2 =0x05.2
#bit RA1 =0x05.1
#bit RA0 =0x05.0
..............
@Ckielstra:
OE is connected to gnd
SCLR is pulled up with 4k7 R
I am using 74HC595
Max F for the chip is 20Mhz
instruction for PIc : 5MHz
So I can remove many delay function
THX so much |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Fri May 09, 2008 8:54 pm |
|
|
HTAluvBeBeo wrote: | PCM: I wrote a definition file .h to define PINs of PIC
.............
#bit RA5 =0x05.5
#bit RA4 =0x05.4
#bit RA3 =0x05.3
#bit RA2 =0x05.2
#bit RA1 =0x05.1
#bit RA0 =0x05.0 | These pin definitions are not compatible with the CCS output functions!!!
There are two methods to set an output:
1) as PCM suggested Code: | #define DATA PIN_A0
output_high(DATA); |
2) or using your defines Code: | #bit RA0 =0x05.0
#define DATA RA0 // pin 14
DATA = 1; |
Mixing both methods will not work!
Both methods result in the same efficient assembly code being generated. Method 1 has the advantage that it is very easy to change your code to another processor as the required port address is not hard coded, you only have to change the processor include file. |
|
|
HTAluvBeBeo
Joined: 23 Feb 2008 Posts: 35
|
|
Posted: Fri May 09, 2008 9:40 pm |
|
|
Thank you so so so much. You point out the right problem. I stimulated with proteus. It seems work well. |
|
|
|