Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
12/21/08 00:27
Read: times


 
#161083 - Thanks
Responding to: ???'s previous message
Thanks for ur valuale suggestion. I am new user of 8052.com and also now only learning about Embedded C programming. I have searched about checksum in google and got some details. I got the following code,

#include <stdio.h>
#include <reg51.h>


unsigned char calc_checksum (
unsigned char *start_addr,
unsigned int len)
{
unsigned char checksum = 0;

for (; len > 0; len--, start_addr++)
{
checksum += *start_addr;
}

return (checksum);
}

/*---------------------------------------------------------
Checksum RANGE = 0x0000-0x3FFE
Checksum BYTE = 0x3FFF
---------------------------------------------------------*/
void main (void)
{
unsigned char checksum;

SCON = 0x50; /* SCON: mode 1, 8-bit UART, enable rcvr */
TMOD |= 0x20; /* TMOD: timer 1, mode 2, 8-bit reload */
TH1 = 221; /* TH1: reload value for 1200 baud @ 16MHz */
TR1 = 1; /* TR1: timer 1 run */
TI = 1; /* TI: set TI to send first char of UART */

checksum = calc_checksum ((unsigned char code *) 0, 0x4000);

if (checksum != 0x80)
{
/*** CHECKSUM FAILED ***/
puts ("Checksum Failedn");
}
else
{
/*** CHECKSUM WORKED ***/
puts ("Checksum Succeededn");
}

while (1);
}

Here can u explain why timers have been used.

List of 14 messages in thread
TopicAuthorDate
Help me for checksum            01/01/70 00:00      
   Do you need someone to breathe for you too?            01/01/70 00:00      
      Score            01/01/70 00:00      
   link: www.google.com            01/01/70 00:00      
      Thanks            01/01/70 00:00      
         So you found someone's code ...            01/01/70 00:00      
            Checksum            01/01/70 00:00      
               don't even go there            01/01/70 00:00      
                  Checksum            01/01/70 00:00      
                     I suggest            01/01/70 00:00      
                        checksum            01/01/70 00:00      
                           This must be VERY difficult.            01/01/70 00:00      
                           the very fact            01/01/70 00:00      
                           re: checksum            01/01/70 00:00      

Back to Subject List