|
|
View previous topic :: View next topic |
Author |
Message |
sahu77
Joined: 08 Sep 2011 Posts: 202
|
need help |
Posted: Tue Jan 28, 2014 3:36 pm |
|
|
This code work fine as i want. This code read ADC from AN0 & display it 7 seg. Here i indecte AN0 port display it 7 seg.
As I-P
But one confusion with me. How can I display AN1, AN2.
Those are need indication O_P & Lod & reading ADC from AN1 & AN2 display it 7 seg.
Code: |
/* 16F7 Configuration dual I|P
O = Output, I = Input RIGHT NOW AS DEMO
_________
MCLR | 1 28 | RB7 --> (O) == A
(I) ADC1 --> AN0 | 2 27 | RB6 --> (O) == B
(I) ADC2 --> AN1 | 3 26 | RB5 --> (O) == C
(I) ADC3 --> AN2 | 4 25 | RB4 --> (O) == E =as D
(I) ADC4 --> AN3 | 5 24 | RB3 --> (O) == D =as E
(I) SW --> RA4 | 6 23 | RB2 --> (O) == F
(I) ADC5 <-- AN4 | 7 22 | RB1 --> (O) == G
Vss | 8 21 | RB0 --> (O) == H
--> OSC1 | 9 20 | Vdd
<-- OSC2 |10 19 | Vss
RL == (O) <-- RC0 |11 18 | RC7 --> (O) == display[3]
== (O) <-- RC1 |12 17 | RC6 --> (O) == display[2]
== (O) <-- RC2 |13 16 | RC5 --> (O) == display[1]
== (O) <-- RC3 |14 15 | RC4 --> (O) ==
---------
WOW ITS OK ON MY PCB
*/
#include <16F72.h>
#device ADC=8
#FUSES NOWDT //No Watch Dog Timer
#FUSES NOBROWNOUT //No brownout reset
//#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES HS
#use delay(crystal=4MHz)
#use FIXED_IO( B_outputs=PIN_B7,PIN_B6,PIN_B5,PIN_B4,PIN_B3,PIN_B2,PIN_B1,PIN_B0 )
#use FIXED_IO( C_outputs=PIN_C7,PIN_C6,PIN_C5,PIN_C4,PIN_C3,PIN_C2,PIN_C1,PIN_C0 )
// RB7=H,RB6=G,RB5=F,RB4=E,RB3=D,RB2=C,RB1=B,RB0=A,
// b0 to b6 port
/*
unsigned char CA[] = {0x3F, 0x06, 0x5B, 0x4F, 0x66, 0x6D, 0x7D, 0x07, 0x7F, 0x6F, 0x00};
//{0xC0, 0xF9, 0xA4, 0xB0, 0x99, 0x92, 0x82, 0xF8, 0x80, 0x90, 0XFF}; // FOR CA
// 0 1 2 3 4 5 6 7 8 9 OFF
// unsigned char CA_P_o [] = {0xCF, 0xBF, 0x8C}; // FOR CA
unsigned char CA_P_o [] = {0x30, 0x40, 0x73}; // FOR CC
// I - P //
// unsigned char CA_P_1 [] = {0xC0, 0xBF, 0x8C}; // FOR CA
unsigned char CA_P_1 [] = {0xBF, 0x40, 0x73}; // FOR CC
// O - P //
// unsigned char CA_P_Lod [] = {0xC7, 0xA3, 0xA1};// FOR CA
unsigned char CA_P_Lod [] = {0x38, 0x5C, 0x5E};//FOR CC
// L o d
*/
#byte port_b=6 /* define the location of register port_b */
#byte port_c=7 /* define the location of register port_c */
#byte PORTA = 0x05
#byte PORTB = 0x06
#byte PORTC = 0x07
#byte TRISA = 0x85
#byte TRISB = 0x86
#byte TRISC = 0x87
#define SPORTB PORTB
#define SPORTC PORTC
#define TICKS_BETWEEN_INTERRUPTS 5000 //5000
#define INTERRUPT_OVERHEAD 35
#define TMR1RESET (0xFFFF-(TICKS_BETWEEN_INTERRUPTS-INTERRUPT_OVERHEAD))
const char CA[11] = {0x3F, 0x06, 0x5B, 0x4F, 0x66, 0x6D, 0x7D, 0x07, 0x7F, 0x6F, 0x00};
//{0xC0, 0xF9, 0xA4, 0xB0, 0x99, 0x92, 0x82, 0xF8, 0x80, 0x90, 0XFF}; // FOR CA
// 0 1 2 3 4 5 6 7 8 9 OFF
const char Column [3] = { 0xDF, 0xBF, 0x7F };// { 0x7f, 0xBF, 0xDF };//{0x01,0x02,0x04};
static char I_P[3] = {0x30, 0x40, 0x73}; // FOR CC
// I - P //
// unsigned char CA_P_1 [] = {0xC0, 0xBF, 0x8C}; // FOR CA
unsigned char O_P [] = {0xBF, 0x40, 0x73}; // FOR CC
// O - P //
static unsigned char ColCount=0x00;
void CPU_SETUP(void);
void Display(void);
void HTO7S(unsigned int32 Num);
int8 i;
unsigned int32 result;
#INT_TIMER1
void Timer1(void)
{
set_timer1(TMR1RESET);
Display();
}
void main()
{
unsigned char i;
CPU_SETUP();
while(true)
{
result=0;
for (i=0;i<20;i++)
{
set_adc_channel(0);
delay_ms(100);
result=result+read_adc();
// result=15*result;
}
// result = 0x3fe;
HTO7S(result);
delay_ms(2000);
}
}
void CPU_SETUP()
{
set_tris_b(0x00);
set_tris_c(0x00);
setup_adc_ports(ALL_ANALOG);
setup_adc(ADC_CLOCK_DIV_32);
setup_timer_1(T1_INTERNAL|T1_DIV_BY_1);
set_timer1(TMR1RESET);
enable_interrupts(GLOBAL);
enable_interrupts(INT_TIMER1);
}
//-------------------------------------
// Display routine
//-------------------------------------
void display()
{if(ColCount>=3){
ColCount=0;}
port_b=I_P[ColCount];
//port_b=0x25;
port_c=Column[ColCount];
ColCount++;}
//--------------------------------------
// Convet HEX 2 byte to 7-Segment code
//--------------------------------------
void HTO7S(unsigned int32 Num)
{
unsigned int32 res;
// I_P[0]=CA[30*Num/10230];
I_P[0]=CA[15*Num/10230];
if (I_P[0]==0x3F)
I_P[0]=0x00;
//res = 30*Num%10230;
res =15* Num%10230;
I_P[1]=CA[10*res/10230];
res=10*res%10230;
I_P[2]=CA[10*res/10230];
}
|
_________________ sahu |
|
|
Mike Walne
Joined: 19 Feb 2004 Posts: 1785 Location: Boston Spa UK
|
|
Posted: Tue Jan 28, 2014 4:11 pm |
|
|
Sit down and THINK.
Start by working out what you want the display to look like.
Say:-
1) Show text "O_P" for 1 second.
2) Show value for AN1 for 1 second.
3) Show text "lod" for 1 second.
4) Show value for AN2 for 1 second.
5) etc then loop back to (1).
When you've decide what you want it to look like, start coding.
Whilst you're at it read the CCS manual.
The CCS way of doing things avoids working on registers like the plague.
Mike
PS How many projects do you have going at the same time? |
|
|
sahu77
Joined: 08 Sep 2011 Posts: 202
|
|
Posted: Wed Jan 29, 2014 9:55 am |
|
|
Mike Walne wrote: | Sit down and THINK.
Start by working out what you want the display to look like.
Say:-
1) Show text "O_P" for 1 second.
2) Show value for AN1 for 1 second.
3) Show text "lod" for 1 second.
4) Show value for AN2 for 1 second.
5) etc then loop back to (1).
When you've decide what you want it to look like, start coding.
Whilst you're at it read the CCS manual.
The CCS way of doing things avoids working on registers like the plague.
Mike
PS How many projects do you have going at the same time? |
yes ur thinking near to me .
those i want to display ,
1) Show text "I_P" for 1 second.
2) Show value for AN0 for 3 second.
3) Show text "O_P" for 1 second.
4) Show value for AN1 for 1 second.
5) Show text "lod" for 1 second.
6) Show value for AN2 for 1 second.
7) etc then loop back to (1).
but confused how can display rest text ( "O_P" & "lod" ) _________________ sahu |
|
|
asmboy
Joined: 20 Nov 2007 Posts: 2128 Location: albany ny
|
MATH results for the index?? |
Posted: Wed Jan 29, 2014 3:37 pm |
|
|
math??
Code: |
const char CA[11]
...
static char I_P[3]
|
then later
Code: |
I_P[0]=CA[15*Num/10230];
|
where Num is a 32 bit integer
and the adc result is 8 bits,
i have some trouble with what is intended by the code.
There is much that is puzzling here, but
my concern is that the ultimate results of the [index] calculations
are in bounds of the declared arrays.. |
|
|
Mike Walne
Joined: 19 Feb 2004 Posts: 1785 Location: Boston Spa UK
|
|
Posted: Wed Jan 29, 2014 3:55 pm |
|
|
sahu77 wrote: | but confused how can display rest text ( "O_P" & "lod" ) |
You've got another thread running in parallel with this one.
You're having difficulty understanding how to drive a multiplexed display.
When you've got it sorted out on your other thread, the solution here will (hopefully) become clearer.
I don't intend going through the process twice.
Mike |
|
|
sahu77
Joined: 08 Sep 2011 Posts: 202
|
|
Posted: Fri Jan 31, 2014 12:17 pm |
|
|
Mike Walne wrote: | sahu77 wrote: | but confused how can display rest text ( "O_P" & "lod" ) |
You've got another thread running in parallel with this one.
You're having difficulty understanding how to drive a multiplexed display.
When you've got it sorted out on your other thread, the solution here will (hopefully) become clearer.
I don't intend going through the process twice.
Mike |
i have got another thread running in parallel with this one. becose there my problem is 7th bit {SEG_(G) <-- RA4} . which re conteced with RA4. _________________ sahu |
|
|
Mike Walne
Joined: 19 Feb 2004 Posts: 1785 Location: Boston Spa UK
|
|
Posted: Fri Jan 31, 2014 5:44 pm |
|
|
sahu77 wrote: | Mike Walne wrote: | sahu77 wrote: | but confused how can display rest text ( "O_P" & "lod" ) |
You've got another thread running in parallel with this one.
You're having difficulty understanding how to drive a multiplexed display.
When you've got it sorted out on your other thread, the solution here will (hopefully) become clearer.
I don't intend going through the process twice.
Mike |
i have got another thread running in parallel with this one. becose there my problem is 7th bit {SEG_(G) <-- RA4} . which re conteced with RA4. |
Please explain the problem with RA4 in a way I can understand.
Mike |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9245 Location: Greensville,Ontario
|
|
Posted: Fri Jan 31, 2014 8:14 pm |
|
|
The problem may be hardware related as that pin RA4 is 'open collector ' NOT TTL according to the datasheet, page 8 ,table 1-1. Unless there's a pullup resistor on that line it won't function like the rest.
You've changed the hardware and NOT corrected the comments at the start of the program, which is very,very confusing!
Most, if not all, 'seven segment LED display' program use the entire port B for the 'segments'( a,b,c,d,e,f,g,dp).It allows for EASY programming and ESY debugging of hardware.Also, there's a LOT of program examples on the web setup this way.
By spliting the segments over two ports, you've got a LOT of extra code that isn't necessary AND unless you deiable all perpipherals to those pins ,can run into 'issues'.
I strongly suggets starting over...
hth
jay |
|
|
Mike Walne
Joined: 19 Feb 2004 Posts: 1785 Location: Boston Spa UK
|
|
Posted: Sat Feb 01, 2014 8:40 am |
|
|
sahu77 wrote: | but confused how can display rest text ( "O_P" & "lod" ) |
Probable simplest solution:-
Create extra elements for your CA[] array. One for each extra character you want.
You've done a 'special' character labeled 'OFF', so should be able to add the code you need.
sahu77 wrote: | i have got another thread running in parallel with this one. becose there my problem is 7th bit {SEG_(G) <-- RA4} . which re conteced with RA4 |
RA4 is not the problem with your 16F676 project. This is NOT the place to discuss a different project.
To avoid further confusion please reply to my latest post in your other thread, I will then respond in that thread, and not here.
Mike |
|
|
sahu77
Joined: 08 Sep 2011 Posts: 202
|
|
Posted: Sat Feb 01, 2014 3:04 pm |
|
|
Mike Walne wrote: | sahu77 wrote: | but confused how can display rest text ( "O_P" & "lod" ) |
Probable simplest solution:-
Create extra elements for your CA[] array. One for each extra character you want.
You've done a 'special' character labeled 'OFF', so should be able to add the code you need.
Mike |
i do there Code: | static char I_P[3] = {0x30, 0x40, 0x73}; // FOR CC
// I - P //
// unsigned char CA_P_1 [] = {0xC0, 0xBF, 0x8C}; // FOR CA
unsigned char O_P [] = {0xBF, 0x40, 0x73}; // FOR CC
// O - P // |
_________________ sahu |
|
|
Mike Walne
Joined: 19 Feb 2004 Posts: 1785 Location: Boston Spa UK
|
|
Posted: Sat Feb 01, 2014 5:05 pm |
|
|
sahu77 wrote: | i do there Code: | static char I_P[3] = {0x30, 0x40, 0x73}; // FOR CC
// I - P //
// unsigned char CA_P_1 [] = {0xC0, 0xBF, 0x8C}; // FOR CA
unsigned char O_P [] = {0xBF, 0x40, 0x73}; // FOR CC
// O - P // |
|
Sorry, missed that nugget (can't see the equivalent for "lod").
There are several ways you could display the text you want.
Probably easier for you to call a Text_To_Symbol() routine instead of HTO7S() when you want to show a text message.
Text_To_Symbol() simply puts the data you want into the I_P[] array.
Mike |
|
|
sahu77
Joined: 08 Sep 2011 Posts: 202
|
|
Posted: Tue Feb 04, 2014 2:52 pm |
|
|
Mike Walne wrote: | sahu77 wrote: | i do there Code: | static char I_P[3] = {0x30, 0x40, 0x73}; // FOR CC
// I - P //
// unsigned char CA_P_1 [] = {0xC0, 0xBF, 0x8C}; // FOR CA
unsigned char O_P [] = {0xBF, 0x40, 0x73}; // FOR CC
// O - P // |
|
Sorry, missed that nugget (can't see the equivalent for "lod").
There are several ways you could display the text you want.
Probably easier for you to call a Text_To_Symbol() routine instead of HTO7S() when you want to show a text message.
Text_To_Symbol() simply puts the data you want into the I_P[] array.
Mike |
pl give one example pl. _________________ sahu |
|
|
Mike Walne
Joined: 19 Feb 2004 Posts: 1785 Location: Boston Spa UK
|
|
Posted: Tue Feb 04, 2014 4:01 pm |
|
|
Nearly a week ago you said you wanted this:-
sahu77 wrote: | yes ur thinking near to me .
those i want to display ,
1) Show text "I_P" for 1 second.
2) Show value for AN0 for 3 second.
3) Show text "O_P" for 1 second.
4) Show value for AN1 for 1 second.
5) Show text "lod" for 1 second.
6) Show value for AN2 for 1 second.
7) etc then loop back to (1).
|
The contents of your IP[] array are continuously displayed as a background task (ie via ISR).
So "1) Show text "I_P" for 1 second." becomes:-
Code: | copy CA_P_o[] array to IP[] array;
delay_ms(1000); |
You've already got a routine for hex to symbol (i.e. your HTO7S() routine).
Adapting it to copy CA_P_o[] array to "I_P" array should be trivial.
Then "2) Show value for AN0 for 3 second. " becomes:-
Code: |
set_adc_channel(0);
delay_ms(1);
result=read_adc();
HTO7S(result);
delay_ms(3000);
| Etc.
No need for me to write any code for you.
OK, there's a lot of repetition.
Get the thing to work as you want it, THEN refine.
Mike |
|
|
sahu77
Joined: 08 Sep 2011 Posts: 202
|
|
Posted: Fri Feb 21, 2014 11:10 am |
|
|
Mike Walne wrote: | Nearly a week ago you said you wanted this:-
sahu77 wrote: | yes ur thinking near to me .
those i want to display ,
1) Show text "I_P" for 1 second.
2) Show value for AN0 for 3 second.
3) Show text "O_P" for 1 second.
4) Show value for AN1 for 1 second.
5) Show text "lod" for 1 second.
6) Show value for AN2 for 1 second.
7) etc then loop back to (1).
|
The contents of your IP[] array are continuously displayed as a background task (ie via ISR).
So "1) Show text "I_P" for 1 second." becomes:-
Code: | copy CA_P_o[] array to IP[] array;
delay_ms(1000); |
You've already got a routine for hex to symbol (i.e. your HTO7S() routine).
Adapting it to copy CA_P_o[] array to "I_P" array should be trivial.
Then "2) Show value for AN0 for 3 second. " becomes:-
Code: |
set_adc_channel(0);
delay_ms(1);
result=read_adc();
HTO7S(result);
delay_ms(3000);
| Etc.
No need for me to write any code for you.
OK, there's a lot of repetition.
Get the thing to work as you want it, THEN refine.
Mike |
Thank you sir
My problem has solved.
Now i add one push sw .
Those function are as:
Quote: |
* Display Procedure:
* step 1
* 1) Show text "I_P" for 1 second.=currentDisplayMode = 1
* 2) Show value for AN0 for 3 second.=currentDisplayMode = 2
* 3) Show text "O_P" for 1 second.=currentDisplayMode = 3
* 4) Show value for AN1 for 1 second.=currentDisplayMode = 4
* 5) etc then loop back to (1).
* its roll over
* step 2
* when I press C0 till 100 ms or 500 ms stop step 1 &
* display hold on currentDisplayMode = 1
* if again C0_PRESSED increment currentDisplayMode +1
* if C0_PRESSED long 1000ms till. then exit from sw scan mode(step 2).
& continuous step 1 |
but sw function not work properly .
Quote: | #INT_TIMER2
void scan_mode(void) // scan_mode with sw
{ while(C0_PRESSED)
{ mode=1;// count=1;// currentDisplayMode = 1;
if(C0_PRESSED){ //agen C0_PRESSED increment currentDisplayMode by 1 =2
mode=mode+1;}// count= count+1;}// currentDisplayMode = currentDisplayMode + 1;}
if(C0_PRESSED){ //agen C0_PRESSED increment currentDisplayMode by 1 =3
mode=mode+1;}//count= count+1;}// currentDisplayMode = currentDisplayMode + 1;}
if(C0_PRESSED){ //agen C0_PRESSED increment currentDisplayMode by 1 =4
mode=mode+1;}//count= count+1;}// currentDisplayMode = currentDisplayMode + 1;}
if(C0_PRESSED){ //agen C0_PRESSED increment currentDisplayMode by 1 =5
mode=mode+1;}//count= count+1;}// currentDisplayMode = currentDisplayMode + 1;}
if(C0_PRESSED){ //agen C0_PRESSED increment currentDisplayMode by 1 =6
mode=mode+1; }//count= count+1;}// currentDisplayMode = currentDisplayMode + 1;}
if(C0_PRESSED){ //agen C0_PRESSED increment currentDisplayMode by 1 =7
mode=mode+1;}//count= count+1;}// currentDisplayMode = currentDisplayMode + 1;}
if(C0_PRESSED){ //agen C0_PRESSED increment currentDisplayMode by 1 =8
mode=mode+1;}// count= count+1;}// currentDisplayMode = currentDisplayMode + 1;}
if(button(PIN_C0, 0, 100, 2, C0, 1))//if C0_PRESSED long 100ms till. then exit form sw scan mode
C0_PRESSED=TRUE;
else
C0_PRESSED=FALSE;
// count= 0;
} } |
_________________ sahu |
|
|
sahu77
Joined: 08 Sep 2011 Posts: 202
|
|
Posted: Sun Feb 23, 2014 1:48 pm |
|
|
pl guide me any body _________________ sahu |
|
|
|
|
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
|