|
|
View previous topic :: View next topic |
Author |
Message |
Gabriel
Joined: 03 Aug 2009 Posts: 1067 Location: Panama
|
|
Posted: Wed Jun 19, 2013 1:04 pm |
|
|
@oxo,
Nice! jejeje
yeah... that code was my first CCS program in '06...
i would never code that - that way again... but hey, it worked! _________________ CCS PCM 5.078 & CCS PCH 5.093 |
|
|
wala.iswara
Joined: 10 Jun 2013 Posts: 21
|
|
Posted: Wed Jun 19, 2013 7:22 pm |
|
|
Dear All,
Many thanks for you are kind attention, you are very nice.
@Mike:
Yes Mike, the picture of my dot matrix minus 1 column. I just connect Q2 of 4017 to column 1st of my 7x4 matrix.
My decade counter is:
HCF4017BE
FULLY STATIC OPERATION
MEDIUM SPEED OPERATION- 12MHz (typ.) AT VDD = 10V
Output drive current 0.36 mA by 4.6 V Vdd.
Output sink current 0.9 mA by 5V Vdd.
The output not have enough current to make 7 LED for 1 column lit brightness. |
|
|
Mike Walne
Joined: 19 Feb 2004 Posts: 1785 Location: Boston Spa UK
|
|
Posted: Thu Jun 20, 2013 11:04 am |
|
|
wala.iswara wrote: | Dear All,
Many thanks for you are kind attention, you are very nice.
@Mike:
Yes Mike, the picture of my dot matrix minus 1 column. I just connect Q2 of 4017 to column 1st of my 7x4 matrix.
My decade counter is:
HCF4017BE
FULLY STATIC OPERATION
MEDIUM SPEED OPERATION- 12MHz (typ.) AT VDD = 10V
Output drive current 0.36 mA by 4.6 V Vdd.
Output sink current 0.9 mA by 5V Vdd.
The output not have enough current to make 7 LED for 1 column lit brightness. |
With the device you're using you don't have enough current capability for even one LED let alone a full column.
Migrating to HCT etc does not solve the problem.
Have you even thought about how much current you actually need?
As shown, on your schematic, you've got 330R current limiting resistors.
Assuming a 5V rail and ~2V across a Red LED, leaves ~3V across the resistor.
That's just shy of 10mA per LED.
Or 60-70mA for a full column.
In other words you've no chance with your column driver.
You'ld be better of using portA to drive PNP or Nchan devices.
Mike
PS Don't even consider using GOTOs |
|
|
wala.iswara
Joined: 10 Jun 2013 Posts: 21
|
|
Posted: Thu Jun 20, 2013 10:13 pm |
|
|
Dear Mike,
I will put Transistor between output pin decade counter and Anode LED for more sinking current.
Anyway, last night i find a code example in CCS C Help file that is using interrupt function with RTCC.
Code: |
/////////////////////////////////////////////////////////////////
/// EX_STWT.C ///
/// This program uses the RTCC (timer0) and interrupts ///
/// to keep a real time seconds counter. A simple stop ///
/// watch function is then implemented. Configure the ///
/// CCS prototype card as follows, insert jumpers from: ///
/// 11 to 17 and 12 to 18. ///
/////////////////////////////////////////////////////////////////
Code removed.
Reason: Forum rule #10
10. Don't post the CCS example code or drivers.
- Forum Moderator
|
I try to adapted that code to blinking the number like above.
Code: | #include <16F628.h>
#fuses XT,NOWDT,NOPUT,NOPROTECT,NOBROWNOUT,NOLVP
#use delay(clock=4000000)
#define Clock_4017 PIN_A0 // -> to pin_14 4017
#define Reset_4017 PIN_A1 // -> to pin_15 4017
#define INTS_PER_SECOND 76 //(20000000/(4*256*256))
byte seconds; //Number of interrupts left
//before a second has elapsed
#int_rtcc
void clock_isr() { //every time the RTCC (timer0)
//overflows (255->0)
//For this program this is apx
//76 times per second.
int count;
if(--count==0) {
++seconds;
count=INTS_PER_SECOND;
}
}
int8 i;
int8 mask[]= { 0b01111110, 0b01111110, 0b00000000, 0b01011110, 0b01011110 }; // 1
void main() {
byte start;
set_rtcc(0);
setup_counters (RTCC_INTERNAL, RTCC_DIV_256);
enable_interrupts (INT_RTCC);
enable_interrupts(GLOBAL);
while(TRUE){
output_a(0b00000000);
output_b(0b00000000);
// Reset 4017 and clearing.
output_high(PIN_A1);
output_low(PIN_A1);
// Blinking the number for 1 second
clock_isr();
start=seconds;
// Displaying number[]
for (i = 0; i <5; i++) {
output_b(mask[i]);
delay_ms(2);
output_b(0b00000000);
// Clock 4017
output_high(PIN_A0);
output_low(PIN_A0);
}
}
}
|
Is my code will work to blink the number for 1 second? |
|
|
Mike Walne
Joined: 19 Feb 2004 Posts: 1785 Location: Boston Spa UK
|
|
Posted: Fri Jun 21, 2013 4:40 am |
|
|
Quote: | Is my code will work to blink the number for 1 second? | Not a snowball in Hades chance.
You're just not learning are you?
Quote: | Dear Mike,
I will put Transistor between output pin decade counter and Anode LED for more sinking current. | I've already told you, a better way is use portA to drive pnp transistors.
[ All the PortA pins can pull down, so A4 open drain is not an issue.
I repeat, the major problem is driving a fully lit column.
Decent pnp switching transistors will pull the anodes to within 100mV of the 5V rail.
Using the 4017 & npn parts as source followers you'll be lucky to get within 600mV.
Plus (a minor point I'll let you off) you're wanting to source current, rather than sink. ]
As far as code goes you're still making wild stabs in the dark.
You've got a 4MHz xtal, which is OK for this code line. Code: | #use delay(clock=4000000) | But it's nonsense for this one! (Which assumes a 20MHz clock!) Code: | #define INTS_PER_SECOND 76 //(20000000/(4*256*256)) |
You've got two defines here you never use, even though I showed you how. Code: | #define Clock_4017 PIN_A0 // -> to pin_14 4017
#define Reset_4017 PIN_A1 // -> to pin_15 4017 |
You're picking random lines from other people's code in the forlorn hope of creating a program which does what you intend.
You're calling the clock_isr() routine from within main!!
In this case you're showing a singular lack of understanding on how interrupts work.
I'm surprised the compiler hasn't complained due to the risk of recursion.
In fact, I think it might be a matter to take up with CCS.
You haven't solved your current problem(s), yet you're going off chasing a new one, without the faintest notion of how to tackle it.
What you are now attempting is way beyond the very limited capabilities you've demonstrated so far.
I've shown you how to make code more readable by indenting, you're just not doing it.
I've told you at least twice already to turn ALL LEDs OFF whilst doing 4017 reset or clock.
Instead, you're again simply ignoring me and doing EXACTLY the opposite.
Then you wonder why others, and I, have run out of patience.
Mike |
|
|
oxo
Joined: 13 Nov 2012 Posts: 219 Location: France
|
|
Posted: Fri Jun 21, 2013 5:06 am |
|
|
Maybe now is a good time to ask how old the OP is Mike. |
|
|
Mike Walne
Joined: 19 Feb 2004 Posts: 1785 Location: Boston Spa UK
|
|
Posted: Fri Jun 21, 2013 6:42 am |
|
|
oxo wrote: | Maybe now is a good time to ask how old the OP is Mike. | Do I have to?
Mike |
|
|
wala.iswara
Joined: 10 Jun 2013 Posts: 21
|
|
Posted: Fri Jun 21, 2013 7:09 am |
|
|
Dear all,
I am stress. Really hard.
Better is iam rest for a moment.
OK. Happy week end for you all.
Good bless. |
|
|
Mike Walne
Joined: 19 Feb 2004 Posts: 1785 Location: Boston Spa UK
|
|
Posted: Fri Jun 21, 2013 9:12 am |
|
|
oxo wrote: | Maybe now is a good time to ask how old the OP is Mike. | I think we've just been told!
And we've had one lot of grandpa pokes already this year.
Mike |
|
|
wala.iswara
Joined: 10 Jun 2013 Posts: 21
|
|
Posted: Sun Jan 19, 2014 7:26 pm |
|
|
Hai all,
i did it. And look nice for me.
Code: | /*******************************************************************************
Counting number 0-9 on 5x7 dot matrix Common Cathode
16F628A & Decade counter 4017
PORTB -> Cathode LED, Output 4017 -> Anoda LED
External Osc. 4MHz X-tall.
CCS
Wawan H. Gufran 01 July 2013
*******************************************************************************/
#include <16F628.h>
#fuses XT,NOWDT,NOPUT,NOPROTECT,NOBROWNOUT,NOLVP
#use delay(clock=4000000)
#byte port_b = 6
#define Clock_4017 PIN_A0 // -> to pin_14 4017
#define Reset_4017 PIN_A1 // -> to pin_15 4017
int8 n0[]= { 0b11000001, 0b10101110, 0b10110110, 0b10111010, 0b11000001 }, // 0
n1[]= { 0b11111110, 0b11111110, 0b10000000, 0b11011110, 0b11011110 }, // 1
n2[]= { 0b01000110, 0b00111010, 0b00111010, 0b00111010, 0b00111100 }, // 2
n3[]= { 0b01001001, 0b00110110, 0b00110110, 0b00110110, 0b00111110 }, // 3
n4[]= { 0b01111011, 0b01100000, 0b01111011, 0b00001011, 0b01110011 }, // 4
n5[]= { 0b00110001, 0b00101110, 0b00101110, 0b00101110, 0b00001110 }, // 5
n6[]= { 0b00110001, 0b00101110, 0b00101110, 0b00101110, 0b01000001 }, // 6
n7[]= { 0b00011111, 0b00101111, 0b00110111, 0b00111000, 0b00111111 }, // 7
n8[]= { 0b01001001, 0b00110110, 0b00110110, 0b00110110, 0b01001001 }, // 8
n9[]= { 0b01000001, 0b00111010, 0b00111010, 0b00111010, 0b01000110 }; // 9
int8 i, loop;
unsigned short mask( unsigned short angka){
switch (angka){
case 0 : // Number 0
for(loop=0;loop<100;loop++){
// Reset 4017 and clearing.
output_high(PIN_A1);
output_low(PIN_A1);
for(i=0;i<5;i++){
port_b=n0[i];
// Clock 4017
output_high(PIN_A0);
delay_ms(2);
output_low(PIN_A0);
delay_ms(2);
}
}
case 1 : // Number 1
for(loop=0;loop<100;loop++){
// Reset 4017 and clearing.
output_high(PIN_A1);
output_low(PIN_A1);
// tampilkan
for(i=0;i<5;i++){
port_b = n1[i];
// Clock 4017
output_high(PIN_A0);
delay_ms(2);
output_low(PIN_A0);
delay_ms(2);
}
}
case 2 : // Number 2
for(loop=0;loop<100;loop++){
// Reset 4017 and clearing.
output_high(PIN_A1);
output_low(PIN_A1);
for(i=0;i<5;i++){
port_b=n2[i];
// Clock 4017
output_high(PIN_A0);
delay_ms(2);
output_low(PIN_A0);
delay_ms(2);
}
}
case 3 : // Number 3
for(loop=0;loop<100;loop++){
// Reset 4017 and clearing.
output_high(PIN_A1);
output_low(PIN_A1);
// tampilkan
for(i=0;i<5;i++){
port_b = n3[i];
// Clock 4017
output_high(PIN_A0);
delay_ms(2);
output_low(PIN_A0);
delay_ms(2);
}
}
case 4 : // Number 4
for(loop=0;loop<100;loop++){
// Reset 4017 and clearing.
output_high(PIN_A1);
output_low(PIN_A1);
for(i=0;i<5;i++){
port_b=n4[i];
// Clock 4017
output_high(PIN_A0);
delay_ms(2);
output_low(PIN_A0);
delay_ms(2);
}
}
case 5 : // Number 5
for(loop=0;loop<100;loop++){
// Reset 4017 and clearing.
output_high(PIN_A1);
output_low(PIN_A1);
// tampilkan
for(i=0;i<5;i++){
port_b = n5[i];
// Clock 4017
output_high(PIN_A0);
delay_ms(2);
output_low(PIN_A0);
delay_ms(2);
}
}
case 6 : // Number 6
for(loop=0;loop<100;loop++){
// Reset 4017 and clearing.
output_high(PIN_A1);
output_low(PIN_A1);
// tampilkan
for(i=0;i<5;i++){
port_b = n6[i];
// Clock 4017
output_high(PIN_A0);
delay_ms(2);
output_low(PIN_A0);
delay_ms(2);
}
}
case 7 : // Number
for(loop=0;loop<100;loop++){
// Reset 4017 and clearing.
output_high(PIN_A1);
output_low(PIN_A1);
// tampilkan
for(i=0;i<5;i++){
port_b = n7[i];
// Clock 4017
output_high(PIN_A0);
delay_ms(2);
output_low(PIN_A0);
delay_ms(2);
}
}
case 8 : // Number 8
for(loop=0;loop<100;loop++){
// Reset 4017 and clearing.
output_high(PIN_A1);
output_low(PIN_A1);
// tampilkan
for(i=0;i<5;i++){
port_b = n8[i];
// Clock 4017
output_high(PIN_A0);
delay_ms(2);
output_low(PIN_A0);
delay_ms(2);
}
}
case 9 : // Number 9
for(loop=0;loop<100;loop++){
// Reset 4017 and clearing.
output_high(PIN_A1);
output_low(PIN_A1);
// tampilkan
for(i=0;i<5;i++){
port_b = n9[i];
// Clock 4017
output_high(PIN_A0);
delay_ms(2);
output_low(PIN_A0);
delay_ms(2);
}
}
}
}
void main(){
int8 nomor;
// ADD ALL PIC TRIS SETUP
setup_comparator(NC_NC_NC_NC); // Comparator OFF
set_tris_a(0);
set_tris_b(0);
delay_ms(500);
while (1){
nomor=mask(nomor);
port_b=nomor;
if(nomor=9)nomor=0;
} //End while
} // End main
|
Thanks for all the support. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19499
|
|
Posted: Mon Jan 20, 2014 1:29 am |
|
|
As a comment, consider making the array two dimensional. Then you need no case statements, and the same code can be used in each case. Smaller, and simpler.
Best Wishes |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Mon Jan 20, 2014 9:02 am |
|
|
Thanks for coming back to the forum and posting your working code for others to learn from.
Just a few more comments: Code: | if(nomor=9)nomor=0; | I didn't check functionality of the code, but first '=' is a bug and should be replaced by a '=='.
Also, nomor is not initialised and never incremented.
Another small suggestion is to use the CCS supplied functions for I/O like output_b(). This way you don't have to set the TRIS registers, the compiler will do it for you. And when moving to another processor where port_b is not at address 6, the code will remain the same when using the CCS function. |
|
|
gpsmikey
Joined: 16 Nov 2010 Posts: 588 Location: Kirkland, WA
|
|
Posted: Mon Jan 20, 2014 11:15 am |
|
|
Ah, my favorite error (not sure why favorite since I have shot myself enough with it ) If you learn to write the conditional as "if(9 == nomor)" instead of "if(nomor == 9)" then when you forget and drop one of the equals signs (which then is always true and sets nomor=9), the compiler will flag it as an error because you are attempting to set 9 = nomor which is not legal. Written the way you did (and most others do), it is still a valid statement, just not what you intended to do (sets nomor = some value instead of testing to see if it is equal to that value). Someone else suggested this years ago in another C forum and I have tried to remember to use it ... it has saved me from myself a number of times
mikey _________________ mikey
-- you can't have too many gadgets or too much disk space !
old engineering saying: 1+1 = 3 for sufficiently large values of 1 or small values of 3 |
|
|
wala.iswara
Joined: 10 Jun 2013 Posts: 21
|
|
Posted: Mon Jan 20, 2014 8:12 pm |
|
|
Thanks all.
@Ttelmah: two dimensional array. Yes, i have to. I was increment the alphabet from A to Z by 26 case statement after change the X-tall to 25 MHz. Big and long.
@ckielstra: Sorry. I delete Code: | if(nomor=9)nomor=0; | in my last code, the nomor just increment, back to 0 after 9, and so on....
Because iam not the
@gpsmikey:
Thanks again all. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19499
|
|
Posted: Tue Jan 21, 2014 2:15 am |
|
|
Slightly puzzled by your comment. What you post can be recoded using a two dimensional array that is exactly the same size as your existing arrays, and the code get 10* shorter/smaller....
You are only doing numbers, not alphabetic. |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|