0% found this document useful (0 votes)
9 views3 pages

Hom 14 3

The document contains multiple C functions for microcontroller programming, specifically for creating delays and controlling output ports. It includes a delay function for 100 microseconds and 1 millisecond, as well as a main function that initializes ports and displays messages on an LCD. The code demonstrates basic input/output operations and timing control in embedded systems.

Uploaded by

tranhongthai0811
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views3 pages

Hom 14 3

The document contains multiple C functions for microcontroller programming, specifically for creating delays and controlling output ports. It includes a delay function for 100 microseconds and 1 millisecond, as well as a main function that initializes ports and displays messages on an LCD. The code demonstrates basic input/output operations and timing control in embedded systems.

Uploaded by

tranhongthai0811
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

void delay_100us(unsigned int n){

while(n--)

TMR0 = 206;

TMR0IF = 0;

T0CS = 0;

TMR0IE = 0;PEIE = 0;GIE = 0;

PSA = 0;

PS2 = 0;

PS1 = 0;

PS0 = 0;

while(TMR0IF==0);

void main(void) {

ANSEL = 0X00;

ANSELH = 0X00;

TRISD = 0X00;

TRISC=0X00;

PORTD=0XFF;

PORTC=0XFF;

while(1){

PORTC=0x8C;

PORTD=0x92;

delay_100us(40000);

PORTD=0XFF;

PORTC=0XFF;

while(1);

}
void delay_1ms(unsigned int n){

while(n--)

TMR0 = 131;

TMR0IF = 0;

T0CS = 0;

TMR0IE = 0;PEIE = 0;GIE = 0;

PSA = 0;

PS2 = 0;

PS1 = 1;

PS0 = 0;

while(TMR0IF==0);

void main(void) {

ANSEL = 0X00;

ANSELH = 0X00;

TRISD = 0X00;

PORTD=0X00;

delay_1ms(300);

while(1){

PORTD=0X80;

delay_1ms(300);

for(unsigned char i=1;i<8;i++){

PORTD = PORTD>>1;

delay_1ms(300);

}
void delay_1ms(unsigned int n){

while(n--)

TMR0 = 131;

TMR0IF = 0;

T0CS = 0;

TMR0IE = 0;PEIE = 0;GIE = 0;

PSA = 0;

PS2 = 0;

PS1 = 1;

PS0 = 0;

while(TMR0IF==0);

void main(void) {

ANSEL=ANSELH=0;

lcd_init();

while(1){

lcd_gotoxy(4,1);

lcd_puts("--2024--");

lcd_gotoxy(1,0);

lcd_puts("HAPPY NEW YEAR");

delay_1ms(1000);

lcd_gotoxy(1,0);

lcd_puts(" ");

delay_1ms(1000);

You might also like