Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Wyświetlacz.c
- *
- * Created: 2019-05-08 13:56:16
- * Author : oem1
- */
- //czestotliwosc zegara glownego
- #define F_CPU 16000000
- #include <avr/interrupt.h>
- #include <avr/io.h>
- #include <util/delay.h>
- #define DEFSEQ_ConfigPortAsOutput(PortName,IniVal) DDR ## PortName=0xff;\
- PORT ## PortName=IniVal;
- #define DEFSEQ_ConfigPinAsOutput(PortName,PinNo) DDR ## PortName|=(1<<PinNo);
- #define DEFSIG_LCD_E_Low PORTA&=~(1<<PA0)
- #define DEFSIG_LCD_E_High PORTA|=(1<<PA0)
- #define DEFSIG_LCD_RS_Comand PORTA&=~(1<<PA1)
- #define DEFSIG_LCD_Rs_Data PORTA|=(1<<PA1)
- #define DEFCMD_LCD_FunctionSet (1<<5)
- #define DEFSET_LCD_DataLenght8 (1<<4)
- #define DEFSET_LCD_2Lines (1<<3)
- #define DEFSET_LCD_FontSize5x8 (0<<2)
- #define DEFCMD_LCD_DisplayControl (1<<3)
- #define DEFSET_LCD_DisplayOn (1<<2)
- #define DEFSET_LCD_CursorOff (0<<1)
- #define DEFSET_LCD_CursorOn (1<<1)
- #define DEFSET_LCD_BlinkingOff (0<<0)
- #define DEFSET_LCD_BlinkingOn (1<<0)
- #define DEFCMD_LCD_ClearDisplay (1<<0)
- #define DEFCMD_LCD_ReturnHome (1<<1)
- #define DEFCMD_LCD_EntryMode (1<<2)
- #define DEFSET_LCD_CursorMoveDirInc (1<<1)
- #define DEFSET_LCD_CursorMoveDirDec (0<<1)
- #define DEFCMD_LCD_SetDDRAMAddress (1<<7)
- #define DEFCMD_LCD_CurDispShift (1<<4)
- #define DEFSET_LCD_DisplayShift (1<<3)
- #define DEFSET_LCD_CursorShift (0<<3)
- #define DEFSET_LCD_ShiftLeft (0<<2)
- #define DEFSET_LCD_ShiftRight (1<<2)
- #define DEFCMD_LCDSetCGRAMAddress (1<<6)
- void Fun_LCD_write(uint8_t ParByte) {
- PORTB = ParByte;
- DEFSIG_LCD_E_High;
- _delay_ms(10);
- DEFSIG_LCD_E_Low;
- }
- void Fun_ShiftDisplayWindow (uint8_t Par_Dirction) {
- DEFSIG_LCD_RS_Comand;
- Fun_LCD_write(DEFCMD_LCD_CurDispShift|DEFSET_LCD_DisplayShift|Par_Dirction);
- _delay_us(40);
- }
- uint8_t sec=00;
- uint8_t
- VAR_String1[]="Druzyna1: 00",
- VAR_String2[]="Druzyna2: 00"
- ;
- volatile uint8_t number1[] = {0};
- volatile uint8_t number2[] = {0};
- volatile uint8_t number3[] = {0};
- volatile uint8_t number4[] = {0};
- #define DEFVAL_CharSi 0
- const uint8_t
- Const_CharSi[8]={ 0b00000000,
- 0b00000100,
- 0b00011111,
- 0b00000010,
- 0b00000100,
- 0b00001000,
- 0b00011111,
- 0b00000000};
- void Fun_LCD_Init (void) {
- // interface configuration
- DEFSEQ_ConfigPortAsOutput (B, 0);
- DEFSEQ_ConfigPinAsOutput (A,0)
- DEFSEQ_ConfigPinAsOutput (A,1)
- DEFSIG_LCD_E_Low;
- //reset sequence
- DEFSIG_LCD_RS_Comand;
- _delay_ms(41);
- Fun_LCD_write (0b00110000);
- _delay_ms(5);
- Fun_LCD_write (0b00110000);
- _delay_us(110);
- Fun_LCD_write (0b00110000);
- _delay_us(110);
- //display configuration
- DEFSIG_LCD_RS_Comand;
- Fun_LCD_write (DEFCMD_LCD_FunctionSet
- |DEFSET_LCD_DataLenght8
- |DEFSET_LCD_2Lines
- |DEFSET_LCD_FontSize5x8);
- _delay_us(40);
- Fun_LCD_write (DEFCMD_LCD_DisplayControl
- |DEFSET_LCD_DisplayOn
- |DEFSET_LCD_CursorOff
- |DEFSET_LCD_BlinkingOff);
- _delay_us(40);
- Fun_LCD_write(DEFCMD_LCD_ClearDisplay);
- _delay_us(40);
- Fun_LCD_write(DEFCMD_LCD_ReturnHome);
- _delay_ms(2);
- Fun_LCD_write(DEFCMD_LCD_EntryMode
- |DEFSET_LCD_CursorMoveDirInc);
- _delay_us(40);
- Fun_LCD_write(DEFCMD_LCD_SetDDRAMAddress|0x00);
- _delay_us(40);
- }
- void Fun_DisplayStringAtPossition (uint8_t* Par_Ptr, uint8_t Par_ByteCount, int8_t Par_Line, int8_t Par_Position) {
- //setting the position
- if((Par_Line !=-1)&&(Par_Position != -1)) {
- DEFSIG_LCD_RS_Comand;
- Fun_LCD_write(DEFCMD_LCD_SetDDRAMAddress|((Par_Line==1?0x00:0x40)+Par_Position));
- _delay_us(40);
- }
- //contents sending
- DEFSIG_LCD_Rs_Data;
- while (Par_ByteCount --) {
- Fun_LCD_write(*Par_Ptr ++);
- _delay_us(40);
- }
- //Fun_LCD_write(*Par_Ptr);
- }
- void Fun_WriteCharFontToCGRAM (const uint8_t* ParPatern, uint8_t ParAddress){
- DEFSIG_LCD_RS_Comand;
- Fun_LCD_write(DEFCMD_LCDSetCGRAMAddress | (ParAddress<<3));
- _delay_us(40);
- DEFSIG_LCD_Rs_Data;
- uint8_t
- LocVAR_Index;
- for (LocVAR_Index=0;LocVAR_Index<8;LocVAR_Index ++ )
- Fun_LCD_write(ParPatern[LocVAR_Index]);
- _delay_us(40);
- }
- /////
- volatile uint8_t key_state=0;
- volatile uint8_t key_state2=0;
- volatile uint8_t key_state3=0;
- volatile uint8_t key_state4=0;
- ISR(TIMER0_COMP_vect)
- {
- //static uint8_t cnt=0;
- //PORTB |=0X0f;
- //PORTA = LED[cnt];
- //PORTB &= ~(1<< cnt);
- //if (++cnt>3) cnt=0;
- //obsluga przycisku
- switch(key_state)
- {
- case 0: if((PINC & 0b10000000)==0) key_state=1;
- break;
- case 1: if((PINC & 0b10000000)==0) key_state=2;
- else key_state=0;
- break;
- case 2:break;
- case 3: if((PINC & 0b10000000)!=0) key_state=4;
- break;
- case 4: if((PINC & 0b10000000)!=0) key_state=0;
- else key_state=3;
- break;
- default: key_state=0;
- }
- switch(key_state2)
- {
- case 0: if((PINC & 0b01000000)==0) key_state2=1;
- break;
- case 1: if((PINC & 0b01000000)==0) key_state2=2;
- else key_state2=0;
- break;
- case 2:break;
- case 3: if((PINC & 0b01000000)!=0) key_state2=4;
- break;
- case 4: if((PINC & 0b01000000)!=0) key_state2=0;
- else key_state2=3;
- break;
- default: key_state2=0;
- }
- switch(key_state3)
- {
- case 0: if((PINC & 0b00100000)==0) key_state3=1;
- break;
- case 1: if((PINC & 0b00100000)==0) key_state3=2;
- else key_state3=0;
- break;
- case 2:break;
- case 3: if((PINC & 0b00100000)!=0) key_state3=4;
- break;
- case 4: if((PINC & 0b00100000)!=0) key_state3=0;
- else key_state3=3;
- break;
- default: key_state3=0;
- }
- switch(key_state4)
- {
- case 0: if((PINC & 0b00010000)==0) key_state4=1;
- break;
- case 1: if((PINC & 0b00010000)==0) key_state4=2;
- else key_state4=0;
- break;
- case 2:break;
- case 3: if((PINC & 0b00010000)!=0) key_state4=4;
- break;
- case 4: if((PINC & 0b00010000)!=0) key_state4=0;
- else key_state4=3;
- break;
- default: key_state4=0;
- }
- }
- ////
- int main(void)
- {
- int sec =50;
- Fun_LCD_Init();
- Fun_WriteCharFontToCGRAM (Const_CharSi, DEFVAL_CharSi);
- VAR_String2[3]=DEFVAL_CharSi;
- VAR_String1[3]=DEFVAL_CharSi;
- Fun_DisplayStringAtPossition (VAR_String1, 9, 1, 0);
- DEFSIG_LCD_Rs_Data;
- uint8_t tmp = number1[0]+'0';
- Fun_LCD_write(tmp);
- _delay_us(40);
- uint8_t tmp1 = number2[0]+'0';
- Fun_LCD_write(tmp1);
- _delay_us(40);
- Fun_DisplayStringAtPossition (VAR_String2, 9, 2, 0);
- uint8_t tmp2 = number3[0]+'0';
- Fun_LCD_write(tmp2);
- _delay_us(40);
- uint8_t tmp3 = number4[0]+'0';
- Fun_LCD_write(tmp3);
- _delay_us(40);
- /* while (1) {
- uint8_t
- LocAR_ShiftIndex;
- for (LocAR_ShiftIndex=0 ; LocAR_ShiftIndex <10; LocAR_ShiftIndex++) {
- Fun_ShiftDisplayWindow (DEFSET_LCD_ShiftLeft);
- _delay_ms(1000);
- }
- for (LocAR_ShiftIndex=0 ; LocAR_ShiftIndex <10; LocAR_ShiftIndex++) {
- Fun_ShiftDisplayWindow (DEFSET_LCD_ShiftRight);
- _delay_ms(1000);
- }
- };
- */
- TCCR0 |= (1<<WGM01);
- TCCR0 |= (1<<CS02) |(1<<CS00);
- OCR0=50;
- //przerwania
- TIMSK |= (1<<OCIE0);
- sei();
- ///////PRZYCISKI
- PORTC|=0b10000000;
- PORTC|=0b01000000;
- PORTC|=0b00100000;
- PORTC|=0b00010000;
- while(1){
- if(key_state==2)
- {
- VAR_String1[11]++;
- if (VAR_String1[11]=='9')
- {
- VAR_String1[10]++;
- VAR_String1[11]=='0';
- }
- Fun_LCD_Init ();
- Fun_DisplayStringAtPossition (VAR_String1, 12, 1,0);
- Fun_DisplayStringAtPossition (VAR_String2, 12, 2, 0);
- key_state=3;
- _delay_ms(2000);
- }
- if(key_state2==2)
- {
- VAR_String2[11]++;
- Fun_LCD_Init ();
- Fun_DisplayStringAtPossition (VAR_String1, 12, 1,0);
- Fun_DisplayStringAtPossition (VAR_String2, 12, 2, 0);
- key_state2=3;
- _delay_ms(2000);
- }
- if(key_state3==2)
- {
- VAR_String1[11]--;
- Fun_LCD_Init ();
- Fun_DisplayStringAtPossition (VAR_String1, 12, 1,0);
- Fun_DisplayStringAtPossition (VAR_String2, 12, 2, 0);
- key_state3=3;
- _delay_ms(2000);
- }
- if(key_state4==2)
- {
- VAR_String2[11]--;
- Fun_LCD_Init ();
- Fun_DisplayStringAtPossition (VAR_String1, 12, 1,0);
- Fun_DisplayStringAtPossition (VAR_String2, 12, 2, 0);
- key_state4=3;
- _delay_ms(2000);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement