You are on page 1of 2

> #include <16f876a.

h> //sets the pic


> #include [/php]
> #use delay(clock=20000000) /* 20mhz crystal */
> #fuses hs,nowdt,noprotect,nolvp //xtal, no watchdog timer,
> no code protection, no low voltage programming (otherwise
> b3 get doesn't work!!)
> #include
> #include
> #include
> #use standard_io(b)
> #define cs1b pin_b4
> #define rs pin_b7
> #define sid pin_b2
> #define sclk pin_b3
> #define rst pin_b1
>
> void lcd_display();
> void lcd_initial();
> void serout(int);
>
> void main()
> {
> //transfer the data in seial mode
> output_low(rst); //reset the driver
> delay_us(1);
> output_high(rst);
> output_high(cs1b);
> delay_us(1);
>
> serout(0xe2);//reset the internal function
>
> lcd_initial();
> while(1)
> {
> lcd_display();
> }
> }
> ////////////
> //funtions//
> ////////////
>
> void lcd_initial()
> {
> output_low(rs);
> serout(0xa0);//select seg output direction (seg1->132),adc=0
> serout(0xc0);//select com output direction (com1->64),shl=0
> serout(0xa3);// select lcd_bias
> serout(0x2f);//switch on the voltage converter,regulator, follower
> delay_ms(2);
> serout(0x27);//select the regulator resistor
> serout(0x81);//1st instruction set reference voltage register
> serout(0x3f);//2nd instruction
> delay_ms(100);//waiting stabilizing the power level
> //serout(0xaf); //turn on the lcd
> }
> void lcd_display(void)
> {
> int k;
> output_low(rs);
> serout(0x40); // initial display line;
> serout(0xb0);
> serout(0x14);//set msl_column address
> serout(0x00);//set lsb_column address
>
> //draw something on page 0 and start at "00"hex column address
> //column address automatically increase 1 after each write data
> display instruction
>
> output_high(rs);
> serout(0xf0); //writing display date
> output_low(rs);>
> serout(0xa6);//reverse display off
> serout(0xa4);//normal display
> serout(0xaf); //turn on the lcd
> }
> void serout(int output)
> {
> int out;
> int n;
> output_low(cs1b); //chip select
> for (n=0;n<8;n++)
> {
> rotate_left(&output, 1);//rotate the msb into 1sb
> out = (0x01&output); //output the new 1sb
> output_bit(sid,out);
> output_low(sclk); //serial input clock
> output_high(sclk);
> }
> delay_us(50);
> output_high(cs1b);
> }

You might also like