21.12.2013 Views

Maskinnära programmering 6B2266

Maskinnära programmering 6B2266

Maskinnära programmering 6B2266

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Testprogram lcd16x1 "Hello world! "<br />

/* lcd16x1.c LCD-display 4 bit data (nibble) conn. to PIC 16F628 */<br />

/* GTC-1601-TR6N0C 1 (2) line 2x8 example: "Hello wo" + "rld! "*/<br />

/* ELFA 75-511-53 c:a 110:- */<br />

/* Internal ic: KS0066U used pins: D4-D7, RS, EN, RD/!WR=0 */<br />

/*<br />

________ ________<br />

| \/ | RD/!WR = 0<br />

D6--|RA2 16F628 RA1|--D5 (only write, wait while busy)<br />

D7--|RA3<br />

RA0|--D4<br />

|RA4 RA7/OSC1|<br />

|RA5/MCLR RA6/OSC2|<br />

+5V--|Vss<br />

Vdd|--GND<br />

|RB0/INT (RB7)/PGD|<br />

|RB1/Rx (RB6)/PGC|<br />

|RB2/Tx<br />

RB5|--RS<br />

EN--|RB3/CCP (RB4)/PGM|<br />

|__________________|<br />

*/<br />

#include "16F628.h"<br />

#pragma config |= 0x3ff0<br />

// use internal 4MHz oscillator<br />

/* I/O-pin definitions */<br />

/* change if you need a pin for a different purpose */<br />

#pragma bit RS @ PORTB.5<br />

#pragma bit EN @ PORTB.3<br />

#pragma bit D7 @ PORTA.3<br />

#pragma bit D6 @ PORTA.2<br />

#pragma bit D5 @ PORTA.1<br />

#pragma bit D4 @ PORTA.0<br />

#include "delays.c"<br />

void delay( char ); // ms delay function from file delays.c<br />

void lcd_init( void );<br />

void lcd_putchar( char );<br />

char text1( char );<br />

char text2( char );<br />

void main( void)<br />

{<br />

CM0=1; CM1=1; CM2=1; // no comparators on PORTA pins<br />

/* I/O-pin direction in/out definitions, change if needed */<br />

TRISB = 0b011.0.1.0.111; // output to RS and EN<br />

TRISA = 0b1111.0000; // output to D4-D7<br />

char i;<br />

lcd_init();<br />

RS = 1; // LCD in character-mode<br />

// display the 8 char text1() sentence<br />

for(i=0; i

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!