need a code, please help

hi,

i’m new to 8051 programming and would really appriciate help,

i need to build a clock for my project an for that i’ve decided to use an 8051 port.

all i need is to get a square wave of precisely 1Hz frequency from any one of the pins any port.

please assist on a suitable Xtal frequency and other calculations, and if possible please help with the code.

remember, i need exactly 1hz freq, so as to get a half sec pulse (50% duty cycle)

The 8051 isn’t as popular on this forum as other chips. However, it sounds like this is a variation of the classic LED blinking program, the “Hello, world!” of the embedded world. A Google of “8051 LED blinker” will get you started. You can use a simple brute force timing approach like the example below, or the timers in the 8051 if you feel more adventurous.

// psuedo code
        set up your IO pins as desired (outputs, most likely)
loop:   turn on the LEDs 
        call delay
        turn off the LEDs
        call delay
        goto loop

delay: 500ms of nops
        return

If you need a half second pulse you need at least a 2hz square wave.

you can used simple delay Subroutines for generating delay or you can use timers for generating delay

check this link for code:

http://www.dnatechindia.com/index.php/Code-Library/