DS Zadaci PDF
DS Zadaci PDF
DS Zadaci PDF
void RotacijaMinus90(){
unsigned int i;
for(i=0;i<50;i++){
RB0=1;
__delay_us(800);
RB0=0;
__delay_us(19200);
}}
void RotacijaPlus90(){
unsigned int i;
for(i=0;i<50;i++){
RB0=1;
__delay_us(2200);
RB0=0;
__delay_us(17800);
}}
void main(void){
TRISB=0;
TRISC=1;
while(1){
if(button==0){
crvena=1;
zelena=0;
RotacijaPlus90();}
else{
crvena=0;
zelena=1;
RotacijaMinus90();
}}}
Bibl.h
if(a & 1) D4 = 1;
else D4 = 0;
if(a & 2) D5 = 1;
else D5 = 0;
if(a & 4) D6 = 1;
else D6 = 0;
if(a & 8) D7 = 1;
else D7 = 0;
/*#define RS RD2
#define EN RD3
#define D4 RD4
#define D5 RD5
#define D6 RD6
#define D7 RD7*/
RS = 0;
Lcd_Port(a);
EN = 1;
__delay_ms(4);
EN = 0;
void Lcd_Clear(){
Lcd_Cmd(0);
Lcd_Cmd(1);
if(a == 1){
temp = 0x80 + b - 1;
z = temp >> 4;
Lcd_Cmd(z);
Lcd_Cmd(y);
temp = 0xC0 + b - 1;
z = temp >> 4;
Lcd_Cmd(z);
Lcd_Cmd(y);
}}
void Lcd_Init(){
Lcd_Port(0x00);
__delay_ms(20);
Lcd_Cmd(0x03);
__delay_ms(5);
Lcd_Cmd(0x03);
__delay_ms(11);
Lcd_Cmd(0x03);
////////////////////////////
Lcd_Cmd(0x02);
Lcd_Cmd(0x02);
Lcd_Cmd(0x08);
Lcd_Cmd(0x00);
Lcd_Cmd(0x0C);
Lcd_Cmd(0x00);
Lcd_Cmd(0x06);
char temp, y;
temp = a&0x0F;
y = a&0xF0;
RS = 1;
EN = 1;
__delay_us(40);
EN = 0;
Lcd_Port(temp);
EN = 1;
__delay_us(40);
EN = 0;}
int i;
Lcd_Write_Char(a[i]);}
void Lcd_Shift_Right(){
Lcd_Cmd(0x01);
Lcd_Cmd(0x0C);}
void Lcd_Shift_Left(){
Lcd_Cmd(0x01);
Lcd_Cmd(0x08);}
void ADC_Init(){
ADCON0bits.CHS0 = 0;
ADCON0bits.CHS1 = 0;
ADCON0bits.CHS2 = 0;
ADCON1bits.ADFM = 1;
ADCON1bits.PCFG0 = 0;
ADCON1bits.PCFG1 = 0;
ADCON1bits.PCFG2 = 0;
ADCON1bits.PCFG3 = 0;
ADCON0bits.GO_DONE = 1;
ADCON0bits.ADON = 1;}
ADCON0 |= channel<<3;
__delay_ms(2);
ADCON0bits.GO_nDONE = 1;
while(ADCON0bits.GO_nDONE);
return((ADRESH<<8)+ADRESL);}
/////////////
#define RS RD2
#define EN RD3
#define D4 RD4
#define D5 RD5
#define D6 RD6
#define D7 RD7
// CONFIG
#pragma config WDTE = OFF // Watchdog Timer Enable bit (WDT disabled)
#pragma config PWRTE = OFF // Power-up Timer Enable bit (PWRT disabled)
#pragma config BOREN = OFF // Brown-out Reset Enable bit (BOR enabled)
#pragma config LVP = ON // Low-Voltage (Single-Supply) In-Circuit Serial Programming Enable bit (RB3 is digital I/O, HV on
MCLR must be used for programming)
#pragma config CPD = OFF // Data EEPROM Memory Code Protection bit (Data EEPROM code protection off)
#pragma config WRT = OFF // Flash Program Memory Write Enable bits (Write protection off; all program memory may be
written to by EECON control)
#pragma config CP = OFF // Flash Program Memory Code Protection bit (Code protection off)
#include <xc.h>
#include <stdio.h>
#include <stdlib.h>
#include "lcd.h"
void UART_Init(){
TRISC6 = 0;
TRISC7 = 1;
SPBRG = ((_XTAL_FREQ/16)/Baud_rate)-1;
BRGH = 1;
SYNC = 0;
SPEN = 1;
TXEN = 1;
CREN = 1;
TX9 = 0;
RX9 = 0;}
while(!TXIF);
TXREG = a;}
char UART_get_char(){
if(OERR){
CREN = 0;
CREN = 1; }
while(!RCIF);
return RCREG;}
UART_send_char(a);}
void menuList(){
printf("\r 3) Trenutna temperatura(koja koristi LM35 senzor da iscita vrijednost i ispise na displeju)\r");}
void main(void){
TRISD = 0;//Lcd
TRISB = 0;//7seg
TRISC = 0;//led,virtualni
unsigned int Display[10] = {0x3F, 0x06, 0x5B, 0x4F, 0x66, 0x6D, 0x7D, 0x07, 0x7F, 0x6F};
char broj = 3;
int i=0;
UART_Init();
ADC_Init();
Lcd_Init();
Lcd_Clear();
char get_value;
while(1){
menuList();
get_value=UART_get_char();
UART_send_char(get_value);
switch(get_value){
case '1':
RC1 = 1;
RC2 = 0;
__delay_ms(1000);
RC2 = 1;
RC1 = 0;
__delay_ms(1000);
Lcd_Clear();
Lcd_Set_Cursor(1,1);
Lcd_Set_Cursor(2,1);
__delay_ms(2000);
break;
case '2':
Lcd_Clear();
Lcd_Set_Cursor(1,1);
Lcd_Write_String("Opcija 2");
/*
for(int j=3;j<9;j++){
PORTB=DISPLAY[j];
__delay_ms(250);
*/
PORTB = Display[i];
__delay_ms(250);}
__delay_ms(2000);
PORTB = Display[i];
__delay_ms(250);
__delay_ms(2000);
PORTB = Display[i];
__delay_ms(250);
if(i %2 != 0){
PORTB = Display[i];
__delay_ms(250); } }
PORTB = Display[0];
__delay_ms(2000);
break;
case '3':
float temp;
int c1,c2,c3,c4;
temp=(ADC_Read(0));
c4 = (temp2 / 1) % 10;
Lcd_Clear();
Lcd_Set_Cursor(1,1);
Lcd_Write_String("TEMPERATURA JE");
Lcd_Set_Cursor(2,1);
Lcd_Write_Char(temp +'0');
/* Lcd_Write_Char(c2 +'0');
Lcd_Write_String(".");
Lcd_Write_Char(c3 +'0');
Lcd_Write_Char(c4 +'0');*/
__delay_ms(1000);
break;
}}
#include <xc.h>
void main(void){
TRISB = 0;
TRISC = 1;
char br = 0;
while(1){
if(!RC2){
if(!RC2){
PORTB = Display[br];
__delay_ms(250);
br++;
br = 0;
}else {
PORTB = Display[br];}}}
// CONFIG
#pragma config WDTE = OFF // Watchdog Timer Enable bit (WDT disabled)
#pragma config PWRTE = OFF // Power-up Timer Enable bit (PWRT disabled)
#pragma config LVP = OFF // Low-Voltage (Single-Supply) In-Circuit Serial Programming Enable bit (RB3 is
digital I/O, HV on MCLR must be used for programming)
#pragma config CPD = OFF // Data EEPROM Memory Code Protection bit (Data EEPROM code protection off)
#pragma config WRT = OFF // Flash Program Memory Write Enable bits (Write protection off; all program
memory may be written to by EECON control)
#pragma config CP = OFF // Flash Program Memory Code Protection bit (Code protection off)
#include <xc.h>
#define EN RD3
#define D4 RD4
#define D5 RD5
#define D6 RD6
#define D7 RD7
#include "lcd.h"
void main(void){
TRISD = 0;
Lcd_Init();
Lcd_Clear();
while(1){
Lcd_Set_Cursor(1,1);
Lcd_Write_String("ARNELA");
__delay_ms(200);
}
#pragma config FOSC = HS // Oscillator Selection bits (HS oscillator)
#pragma config WDTE = OFF // Watchdog Timer Enable bit (WDT disabled)
#pragma config PWRTE = OFF // Power-up Timer Enable bit (PWRT disabled)
#pragma config LVP = OFF // Low-Voltage (Single-Supply) In-Circuit Serial Programming Enable bit (RB3 is
digital I/O, HV on MCLR must be used for programming)
#pragma config CPD = OFF // Data EEPROM Memory Code Protection bit (Data EEPROM code protection off)
#pragma config WRT = OFF // Flash Program Memory Write Enable bits (Write protection off; all program
memory may be written to by EECON control)
#pragma config CP = OFF // Flash Program Memory Code Protection bit (Code protection off)
#include <xc.h>
#include <stdio.h>
#include <stdlib.h>
#define s1 RC0
#define s2 RC1
#define s3 RC2
#define s4 RC3
void main(void){
PORTB = 0;
TRISB = 0;
PORTC = 0;
TRISC = 0;
PORTD = 0;
TRISD = 0;
char DISPLAY[10] = {0x3F, 0x06, 0x5B, 0x4F, 0x66, 0x6D, 0x7D, 0x07, 0x7F, 0x6F};
for(int j=0;j<6;j++){
for(int k=0;k<6;k++){
for(int z=0;z<10;z++){
for(int a=0;a<10;a++){
if(i==0 && j==0 && k==5 && z==9 ){
CRVENA = 1;
ZELENA = 0;
CRVENA = 1;
ZELENA = 0; }
s2=1;
s3=1;
s4=1;
PORTB=DISPLAY[z];
s1=0;
__delay_ms(5);
s1=1;
s3=1;
s4=1;
PORTB=DISPLAY[k];
s2=0;
__delay_ms(5);
s1=1;
s2=1;
s4=1;
PORTB=DISPLAY[j];
s3=0;
__delay_ms(5);
s1=1;
s2=1;
s3=1;
PORTB=DISPLAY[i];
s4=0;
__delay_ms(5);
}}}}}}
BROJANJE OD 0 -9
#pragma config WDTE = OFF // Watchdog Timer Enable bit (WDT disabled)
#pragma config PWRTE = OFF // Power-up Timer Enable bit (PWRT disabled)
#pragma config LVP = OFF // Low-Voltage (Single-Supply) In-Circuit Serial Programming Enable bit (RB3 is
digital I/O, HV on MCLR must be used for programming)
#pragma config CPD = OFF // Data EEPROM Memory Code Protection bit (Data EEPROM code protection off)
#pragma config WRT = OFF // Flash Program Memory Write Enable bits (Write protection off; all program
memory may be written to by EECON control)
#pragma config CP = OFF // Flash Program Memory Code Protection bit (Code protection off)
#include <xc.h>
#include <stdio.h>
#include <stdlib.h>
unsigned char const DISPLAY[10] = {0x3F, 0x06, 0x5B, 0x4F, 0x66, 0x6D, 0x7D, 0x07, 0x7F, 0x6F};
void UART_init(void){
TRISC6 = 0;
TRISC7 = 1;
SPBRG = ((_XTAL_FREQ/16)/Baud_rate)-1;
BRGH = 1;
SYNC = 0;
SPEN = 1;
TXEN = 1;
CREN = 1;
TX9 = 0;
RX9 = 0;
while(!TXIF);
TXREG = a; }
char UART_get_char(){
if(OERR){
CREN = 0;
CREN = 1;}
while(!RCIF);
return RCREG;}
UART_send_char(a);}
void showList(){
printf("\r");
TRISB=0;
UART_init();
char get_value;
int vrijednost;
char broj1=0;
char broj2=9;
do {
showList();
get_value=UART_get_char();
UART_send_char(get_value);
if(vrijednost==1){
while(1){
PORTB=(DISPLAY[broj1]);
__delay_ms(250);
broj1++;
if(broj1>9){
break; }}}
else if(vrijednost==2){
while(1){
PORTB=DISPLAY[broj2];
__delay_ms(250);
broj2--;
if(broj2==0){
break; }}}
while(get_value!=3);}
VIRTUAL SABIRANJE
#pragma config WDTE = OFF // Watchdog Timer Enable bit (WDT disabled)
#pragma config PWRTE = OFF // Power-up Timer Enable bit (PWRT disabled)
#pragma config LVP = OFF // Low-Voltage (Single-Supply) In-Circuit Serial Programming Enable bit (RB3 is
digital I/O, HV on MCLR must be used for programming)
#pragma config CPD = OFF // Data EEPROM Memory Code Protection bit (Data EEPROM code protection off)
#pragma config WRT = OFF // Flash Program Memory Write Enable bits (Write protection off; all program
memory may be written to by EECON control)
#pragma config CP = OFF // Flash Program Memory Code Protection bit (Code protection off)
#include <xc.h>
#include <stdio.h>
#include <stdlib.h>
void main(void) {
TRISB = 0x00;
RB0 = 0;
RB1 = 0;
UART_init();
char get_value;
char get_value_1;
char get_value_2;
int value_1;
int value_2;
int rezultat;
char rezultat_krajnji;
do{
printf("\r Odaberite jedan broj:\r");
get_value_1=UART_get_char();
UART_send_char(get_value_1);
get_value_2=UART_get_char();
UART_send_char(get_value_2);
printf("\r 1. Sabiranje");
printf("\r 2. Oduzimanje");
printf("\r 3. Mnozenje");
get_value=UART_get_char();
UART_send_char(get_value);
switch(get_value){
case '1':
rezultat = value_1+value_2;
UART_send_char(rezultat_krajnji);
if(rezultat>5){
RB0 = 1;
RB1 = 0; }
else if(rezultat<5){
RB1 = 1;
RB0 = 0; }
break;
case '2':
rezultat = value_1-value_2;
UART_send_char(rezultat_krajnji);
if(rezultat>5){
RB0 = 1;
RB1 = 0; }
else if(rezultat<5){
RB1 = 1;
RB0 = 0; }
break;
case '3':
rezultat = value_1*value_2;
UART_send_char(rezultat_krajnji);
if(rezultat>5){
RB0 = 1;
RB1 = 0; }
else if(rezultat<5){
RB1 = 1;
RB0 = 0; }
break; }}
while(get_value!=4); }