This super simple circuit will now allow us to experiment with displaying something on the screen. download the sourcecode and we will have a look at what is going on.
You can download that file here
Now the first thing to mention with this piece of sourcecode is that we are operating the internal oscillator at 4MHz. This means that we are running at 1Mips (1 million instructions per second) and therfor this means that it takes 1us to execute one instruction.
This makes it a little easier for us to count clock cycles (remember that we have 64us for every ONE scanline - and 52us of that time is our visible image data)
So the first thing we need to do is send out our 4us sync pulse. This is contained within this piece of code:
clrf PORTB
nop
nop
movlw b'00000001'
the first 1us is contained in the clrf PORTB instruction. so we are sending ZERO volts through to the screen. we then have two NOP statements which holds the ZERO volts there for a further TWO microseconds. the last instruction serves two purposes. it gets us ready for the next 8us pulse by storing b'00000001' into the w register. it also takes 1us to perform this instruction so it also acts as our last 1us delay in the total of 4us in the sync pulse.
Now our first 4us is up, we then move onto holding b'00000001' on PORTB for 8us
movwf PORTB
nop
nop
nop
nop
nop
nop
movlw b'00000010'
The first instruction copies what was in the w register (b'00000001') into PORTB. this instruction takes 1us. then we have a set of 6 nops which delay for an extra 6us. So now we have taken 7us to do all this. We just need to hold it for one more microsecond. We do this with the final instruction which is movlw b'00000010' this serves two purposes it gets us ready to send a voltage greater than 0.3volts to the screen. (which means that we will actually be able to see something in the next piece of code) this line of code also takes 1us so it acts as the last 1us in the 8us delay.
Now that we have finished the sync pulses, the next 52us is our visible data. so whatever we put on PORTB from now on, will be displayed on the screen. The remainder of the code is dedicated to sending out different combinations of 1's and 0's to PORTB (namely to pins 0 and 1) this has the effect of varying the voltage going to the screen by use of the voltage divider resistor network.
We can have one of four combinations at any one time. these being 00, 01, 10 or 11. 00 and 01 will give us black on the screen, whereas anything above 01 will give us a voltage great enough to display a shade of grey. So we first send 10 which is a dark grey, we hold it there for a while then we change it to 11 which is white. we hold it there for a while and then go back to 10. we hold it there for a while and then finally we send out 01 which is black.