Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Capturing digits from PORTB and send it to screen via UART

Status
Not open for further replies.

Subashini

Newbie level 4
Joined
Jun 15, 2012
Messages
6
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,368
The programme I have done so far works except that it cannot capture the output which is 88 (integer) from PORTB to the screen via UART. Can someone tell me what is the problem with my code that it cannot display the integer but it can send all the characters. When I compile there is no error. But it still cannot display any result.


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/*
  PIC16F628A at 4.0 MHz external clock, MCLR enabled
*/
 
 
sbit IR_Tx at RA3_bit;
sbit DD0_Set at RA2_bit;
sbit DD1_Set at RA1_bit;
sbit DD2_Set at RA0_bit;
sbit start at RB7_bit;
unsigned short j, DD0, DD1, DD2, DD3;
unsigned short pulserate, pulsecount;
unsigned int i;
//-------------- Function to Return mask for common anode 7-seg. display
unsigned short mask(unsigned short num) {
 switch (num) {
 case 0 : return 0xC0;
 case 1 : return 0xF9;
 case 2 : return 0xA4;
 case 3 : return 0xB0;
 case 4 : return 0x99;
 case 5 : return 0x92;
 case 6 : return 0x82;
 case 7 : return 0xF8;
 case 8 : return 0x80;
 case 9 : return 0x90;
 } //case end
}
 
void delay_debounce(){
 Delay_ms(300);
}
 
void delay_refresh(){
 Delay_ms(5);
}
 
void countpulse(){
 IR_Tx = 1;
 delay_debounce();
 delay_debounce();
 TMR0=0;
 Delay_ms(15000);  // Delay 1 Sec
 IR_Tx = 0;
 pulserate = 22*4;
}
 
void display(){
  DD0 = pulserate%10;
  DD0 = mask(DD0);
  DD1 = (pulserate/10)%10;
  DD1 = mask(DD1);
  DD2 = pulserate/100;
  DD2 = mask(DD2);
  for (i = 0; i<=180*j; i++) {
    DD0_Set = 0;
    DD1_Set = 1;
    DD2_Set = 1;
    PORTB = DD0;
    delay_refresh();
    DD0_Set = 1;
    DD1_Set = 0;
    DD2_Set = 1;
    PORTB = DD1;
    delay_refresh();
    DD0_Set = 1;
    DD1_Set = 1;
    DD2_Set = 0;
    PORTB = DD2;
    delay_refresh();
    }
  DD2_Set = 1;
}
 
 void newline()
{
 UART1_Write(13); // Carriage Return
 UART1_Write(10); // Line Feed
}
 
void main() {
 unsigned char MyError, Temp;
 UART1_Init(9600);
 Delay_ms(100);
 UART1_Write_Text("Ready to know your heartbeat ?? :D ");
 Temp = DD0,DD1,DD2;
 newline();
 UART1_Write_Text("Your Heartbeat rate is : ");
 UART1_Write(Temp);
 newline();
 newline();
 
 CMCON = 0x07;    // Disable Comparators
 TRISA = 0b00110000; // RA4/T0CKI input, RA5 is I/P only
 TRISB = 0b10000000; // RB7 input, rest output
 OPTION_REG = 0b00101000; // Prescaler (1:1), TOCS =1 for counter mode
 pulserate = 0;
 j = 1;
 display();
 
  do {
  if(!start){
   delay_debounce();
   countpulse();
   j= 3;
   display();
  }
 } while(1);  // Infinite loop
 }

 
Last edited by a moderator:

It suppose to send the number 88 to the screen via uart.
 

This is wrong.

Code:
Delay_ms(15000);  // Delay 1 Sec

It should be

Code:
Delay_ms(1000);

Have you set the proper baud rate in hyperterminal?
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top